From a1a8e1339f0cb28e47812b69cf4b8c3861e2655c Mon Sep 17 00:00:00 2001 From: attila Date: Thu, 3 Feb 2022 17:33:05 +0100 Subject: [PATCH] PopupMenu: Fix click-through from submenu Previously it was possible to inadvertently activate a menu item by clicking on a submenu item that was drawn on top of the parent menu. The root cause was that hide() initiates an asynchronous mechanism through exitModalState() that eventually destroys the MenuWindow, but the MouseSourceState timer callbacks and event handlers sometimes still had a chance to do a state update. Since the submenus have just been destroyed the update could mistakenly conclude to activate one of the items of the now lone parent. --- modules/juce_gui_basics/menus/juce_PopupMenu.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index 22668e1044a6..a03e01b6bc2e 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -541,6 +541,7 @@ struct MenuWindow : public Component auto resultID = options.hasWatchedComponentBeenDeleted() ? 0 : getResultItemID (item); exitModalState (resultID); + exitingModalState = true; if (makeInvisible && deletionChecker != nullptr) setVisible (false); @@ -739,6 +740,9 @@ struct MenuWindow : public Component if (! treeContains (currentlyModalWindow)) return false; + if (exitingModalState) + return false; + return true; } @@ -1323,6 +1327,7 @@ struct MenuWindow : public Component uint32 windowCreationTime, lastFocusedTime, timeEnteredCurrentChildComp; OwnedArray mouseSourceStates; float scaleFactor; + bool exitingModalState = false; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MenuWindow) };