BMenu: Lock the looper before calling _AddItem().
Otherwise, we could wind up in a state where the list of items is being concurrently accessed, which is invalid. Hopefully fixes #18256.
This commit is contained in:
@@ -726,11 +726,19 @@ BMenu::AddItem(BMenuItem* item, int32 index)
|
|||||||
"be called if the menu layout is not B_ITEMS_IN_MATRIX");
|
"be called if the menu layout is not B_ITEMS_IN_MATRIX");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item == NULL || !_AddItem(item, index))
|
if (item == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
const bool locked = LockLooper();
|
||||||
|
|
||||||
|
if (!_AddItem(item, index)) {
|
||||||
|
if (locked)
|
||||||
|
UnlockLooper();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
if (LockLooper()) {
|
if (locked) {
|
||||||
if (!Window()->IsHidden()) {
|
if (!Window()->IsHidden()) {
|
||||||
_LayoutItems(index);
|
_LayoutItems(index);
|
||||||
_UpdateWindowViewSize(false);
|
_UpdateWindowViewSize(false);
|
||||||
@@ -754,13 +762,18 @@ BMenu::AddItem(BMenuItem* item, BRect frame)
|
|||||||
if (item == NULL)
|
if (item == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
const bool locked = LockLooper();
|
||||||
|
|
||||||
item->fBounds = frame;
|
item->fBounds = frame;
|
||||||
|
|
||||||
int32 index = CountItems();
|
int32 index = CountItems();
|
||||||
if (!_AddItem(item, index))
|
if (!_AddItem(item, index)) {
|
||||||
|
if (locked)
|
||||||
|
UnlockLooper();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (LockLooper()) {
|
if (locked) {
|
||||||
if (!Window()->IsHidden()) {
|
if (!Window()->IsHidden()) {
|
||||||
_LayoutItems(index);
|
_LayoutItems(index);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
|||||||
Reference in New Issue
Block a user