[Scummvm-git-logs] scummvm branch-2-8 -> b9fecf50c550c995146db09a1e2387308cfc0a34

sev- noreply at scummvm.org
Sat Dec 16 20:15:39 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b9fecf50c5 GRAPHICS: MACGUI: Avoid recursion in Mac menu event processing


Commit: b9fecf50c550c995146db09a1e2387308cfc0a34
    https://github.com/scummvm/scummvm/commit/b9fecf50c550c995146db09a1e2387308cfc0a34
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2023-12-16T21:15:33+01:00

Commit Message:
GRAPHICS: MACGUI: Avoid recursion in Mac menu event processing

When moving the mouse through the menu bar, over a part that's not
occupied by menu items, the Mac menu class will start calling
processEvent() recursively. This is bad for two reasons: During the
recursion (which can easily reach a depth of dozens or even hundreds of
calls) there is no delay, so it will use 100% CPU. And once the
recursion unwinds, all the delays will come at once.

This moves the call to eventLoop() to after the first event has been
fully processed. Hopefully that will have approximately the same desired
effect, without any of the bad side effects.

Changed paths:
    graphics/macgui/macmenu.cpp
    graphics/macgui/macwindowmanager.cpp


diff --git a/graphics/macgui/macmenu.cpp b/graphics/macgui/macmenu.cpp
index ab5fa3a81be..7507bc4641d 100644
--- a/graphics/macgui/macmenu.cpp
+++ b/graphics/macgui/macmenu.cpp
@@ -1285,16 +1285,6 @@ bool MacMenu::mouseClick(int x, int y) {
 			_wm->activateMenu();
 
 		setActive(true);
-
-		if (_wm->_mode & kWMModalMenuMode) {
-			draw(_wm->_screen);
-			eventLoop();
-
-			// Do not do full refresh as we took care of restoring
-			// the screen. WM is not even aware we were drawing.
-			_wm->setFullRefresh(false);
-		}
-
 		return true;
 	}
 
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index e60a749cdbf..c2fcdfd1884 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -1057,8 +1057,18 @@ bool MacWindowManager::processEvent(Common::Event &event) {
 	}
 
 	// Menu gets events first for shortcuts and menu bar
-	if (_menu && _menu->processEvent(event))
+	if (_menu && _menu->processEvent(event)) {
+		if (_mode & kWMModalMenuMode) {
+			_menu->draw(_screen);
+			_menu->eventLoop();
+
+			// Do not do full refresh as we took care of restoring
+			// the screen. WM is not even aware we were drawing.
+			setFullRefresh(false);
+		}
+
 		return true;
+	}
 
 	if (_activeWindow != -1) {
 		if ((_windows[_activeWindow]->isEditable() && _windows[_activeWindow]->getType() == kWindowWindow &&




More information about the Scummvm-git-logs mailing list