1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Component: Add an assertion to check that the component remains alive when entering modal state

This commit is contained in:
reuk 2022-10-25 13:30:34 +01:00
parent 3061876e0d
commit 697643c0b6
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -1769,6 +1769,8 @@ void Component::enterModalState (bool shouldTakeKeyboardFocus,
// thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
SafePointer safeReference { this };
if (! isCurrentlyModal (false))
{
// While this component is in modal state it may block other components from receiving
@ -1776,6 +1778,13 @@ void Component::enterModalState (bool shouldTakeKeyboardFocus,
// we must manually force the mouse to "leave" blocked components.
ComponentHelpers::sendMouseEventToComponentsThatAreBlockedByModal (*this, &Component::internalMouseExit);
if (safeReference == nullptr)
{
// If you hit this assertion, the mouse-exit event above has caused the modal component to be deleted.
jassertfalse;
return;
}
auto& mcm = *ModalComponentManager::getInstance();
mcm.startModal (this, deleteWhenDismissed);
mcm.attachCallback (this, callback);