[Solved] NativeMessageBox crashes after the second call

A bug that I noticed on both iOS and Android (didn't test on other platforms): if you call NativeMessageBox  with a callback, the second call with crash as the callback is deleted. This wasn't happning in previous Juce versions.


To fix this on Android I had to remove line 671 of Juce_android_windowsing.cpp:

delete callback;

On iOS, I replaced line 162:

ScopedPointer<ModalComponentManager::Callback> callback;


ModalComponentManager::Callback* callback;

Now the crash doesn't occur anymore.

...are you sure you're not just calling it wrongly?

You need to create a new callback object, and give it to the method for deletion later, in which case I think the code should work correctly (?) Are you passing it a local stack object as the callback, or deleting it yourself in some other way?

Ah, that must be because I instanciate the callback only once, instead of creating a new instance at each NativeMessageBox call. It used to work before because you didn't delete the callback, I get it now.


Edit: FWIW, my design pattern was: each class calling a NativeMessageBox uses its own ModalComponentManager::Callback member, so I instanciate it once in the constructor, delete it in the destructor, and use it for every NativeMessageBox call in the methods.