Adding text field to an alert box on Android with no contents causes a crash


#1

Hi, fine on other OSes.

auto *p_alert = new AlertWindow( "Trial License", "Please enter your email address", AlertWindow::AlertIconType::NoIcon );
p_alert->addTextEditor( "email", "" );
p_alert->enterModalState( true, ModalCallbackFunction::create( [ = ]( int res ) {

Causes a crash. Changing the email default to “x” or any other string is fine.

Cheers


#2

I don’t know why this is happening, it’s really strange. However for the time being you can either make your AlertWindow a member variable and do the addTextEditor() setup in its parent’s constructor and then call enterModalState() later or you can add a small delay between addTextEditor() and enterModalState() which oddly makes the crash disappear. Something like this:

auto *p_alert = new AlertWindow( "Trial License", "Please enter your email address", AlertWindow::AlertIconType::NoIcon );
p_alert->addTextEditor( "email", "" );

Timer::callAfterDelay (100, [=] { p_alert->enterModalState (true, ModalCallbackFunction::create ([=](int) { })); });

I have no idea why this is working though, I’ll try to dig into this a bit more.