mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
iOS: Fix native message box leak when no callback is provided
This commit is contained in:
parent
b620bf1d43
commit
112f8999fd
2 changed files with 16 additions and 7 deletions
|
|
@ -437,8 +437,11 @@ void LookAndFeel::playAlertSound()
|
|||
class iOSMessageBox
|
||||
{
|
||||
public:
|
||||
iOSMessageBox (const MessageBoxOptions& opts, std::unique_ptr<ModalComponentManager::Callback>&& cb)
|
||||
: callback (std::move (cb))
|
||||
iOSMessageBox (const MessageBoxOptions& opts,
|
||||
std::unique_ptr<ModalComponentManager::Callback>&& cb,
|
||||
bool deleteOnCompletion)
|
||||
: callback (std::move (cb)),
|
||||
shouldDeleteThis (deleteOnCompletion)
|
||||
{
|
||||
if (currentlyFocusedPeer != nullptr)
|
||||
{
|
||||
|
|
@ -480,10 +483,10 @@ public:
|
|||
result = buttonIndex;
|
||||
|
||||
if (callback != nullptr)
|
||||
{
|
||||
callback->modalStateFinished (result);
|
||||
|
||||
if (shouldDeleteThis)
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -501,6 +504,7 @@ private:
|
|||
|
||||
int result = -1;
|
||||
std::unique_ptr<ModalComponentManager::Callback> callback;
|
||||
const bool shouldDeleteThis;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (iOSMessageBox)
|
||||
};
|
||||
|
|
@ -517,13 +521,18 @@ static int showDialog (const MessageBoxOptions& options,
|
|||
{
|
||||
jassert (mapFn != nullptr);
|
||||
|
||||
iOSMessageBox messageBox (options, nullptr);
|
||||
iOSMessageBox messageBox (options, nullptr, false);
|
||||
return mapFn (messageBox.getResult());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
const auto showBox = [options, callbackIn, mapFn] { new iOSMessageBox (options, AlertWindowMappings::getWrappedCallback (callbackIn, mapFn)); };
|
||||
const auto showBox = [options, callbackIn, mapFn]
|
||||
{
|
||||
new iOSMessageBox (options,
|
||||
AlertWindowMappings::getWrappedCallback (callbackIn, mapFn),
|
||||
true);
|
||||
};
|
||||
|
||||
if (MessageManager::getInstance()->isThisTheMessageThread())
|
||||
showBox();
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ private:
|
|||
[alert setInformativeText: juceStringToNS (options.getMessage())];
|
||||
|
||||
[alert setAlertStyle: options.getIconType() == MessageBoxIconType::WarningIcon ? NSAlertStyleCritical
|
||||
: NSAlertStyleInformational];
|
||||
: NSAlertStyleInformational];
|
||||
|
||||
const auto button1Text = options.getButtonText (0);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue