diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index cc7577c5db..7eb1d58918 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -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);