From c4793b242c5c4c7bcebc4a2702ff139365f017ef Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 17 Dec 2014 10:20:10 +0100 Subject: [PATCH] fix adding or removing items to an open BMenu The menu would try to relayout itself, but fail to get the supermenu bounds as the looper for it was not locked in that case. This fixes the crash with two downsides: * The menu width isn't adjusted to match the parent menu (mostly visible in BMenuFields) * There is some flickering as the menu is updated Fixes #9863 (Network prefs part). --- src/kits/interface/Menu.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index 8d59153288..58aaeb8c15 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -2140,8 +2140,16 @@ BMenu::_ComputeLayout(int32 index, bool bestFit, bool moveItems, BRect parentFrame; BRect* overrideFrame = NULL; if (dynamic_cast<_BMCMenuBar_*>(Supermenu()) != NULL) { - parentFrame = Supermenu()->Bounds(); - overrideFrame = &parentFrame; + // When the menu is modified while it's open, we get here in a + // situation where trying to lock the looper would deadlock + // (the window is locked waiting for the menu to terminate). + // In that case, just give up on getting the supermenu bounds + // and keep the menu at the current width and position. + if (Supermenu()->LockLooperWithTimeout(0) == B_OK) { + parentFrame = Supermenu()->Bounds(); + Supermenu()->UnlockLooper(); + overrideFrame = &parentFrame; + } } _ComputeColumnLayout(index, bestFit, moveItems, overrideFrame,