summaryrefslogtreecommitdiff
path: root/LibGUI
diff options
context:
space:
mode:
authorChristopher Dumas <christopherdumas@gmail.com>2019-05-23 19:31:00 -0700
committerAndreas Kling <awesomekling@gmail.com>2019-05-24 04:31:00 +0200
commit982335475412083f5ae5386cb332f75dee4042fb (patch)
tree496eb365eda867db69d4b27715527512600c04f1 /LibGUI
parentebf645d72a12e3eedbbda9c976fe2a7e2018d818 (diff)
downloadserenity-982335475412083f5ae5386cb332f75dee4042fb.zip
LibGUI: Don't crash when updating menu item that's not in the window server (#83)
Don't crash when updating menu item that's not in the window server. Menu Items begin with an invalid ID of -1, and only get a valid ID if the menu they are attached to is added to the window server. They don't send updates to the server unless they have a valid ID. Fixes #82
Diffstat (limited to 'LibGUI')
-rw-r--r--LibGUI/GMenu.cpp3
-rw-r--r--LibGUI/GMenu.h2
-rw-r--r--LibGUI/GMenuItem.cpp2
-rw-r--r--LibGUI/GMenuItem.h2
4 files changed, 7 insertions, 2 deletions
diff --git a/LibGUI/GMenu.cpp b/LibGUI/GMenu.cpp
index c97d5cbddf..592c709fda 100644
--- a/LibGUI/GMenu.cpp
+++ b/LibGUI/GMenu.cpp
@@ -32,6 +32,7 @@ GMenu::~GMenu()
void GMenu::add_action(Retained<GAction> action)
{
m_items.append(make<GMenuItem>(m_menu_id, move(action)));
+ dbgprintf("MenuItem Menu ID: %d\n", m_menu_id);
}
void GMenu::add_separator()
@@ -70,6 +71,7 @@ int GMenu::realize_menu()
auto response = GEventLoop::current().sync_request(request, WSAPI_ServerMessage::Type::DidCreateMenu);
m_menu_id = response.menu.menu_id;
+ dbgprintf("GMenu: Realizing menu! New menu ID: %d", m_menu_id);
ASSERT(m_menu_id > 0);
for (int i = 0; i < m_items.size(); ++i) {
auto& item = *m_items[i];
@@ -79,6 +81,7 @@ int GMenu::realize_menu()
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::AddMenuSeparator;
request.menu.menu_id = m_menu_id;
+ dbgprintf("MenuItem [New] Menu ID: %d\n", m_menu_id);
GEventLoop::current().sync_request(request, WSAPI_ServerMessage::Type::DidAddMenuSeparator);
continue;
}
diff --git a/LibGUI/GMenu.h b/LibGUI/GMenu.h
index a5280393dc..1eb741de4b 100644
--- a/LibGUI/GMenu.h
+++ b/LibGUI/GMenu.h
@@ -33,7 +33,7 @@ private:
int realize_menu();
void unrealize_menu();
- int m_menu_id { 0 };
+ int m_menu_id { -1 };
String m_name;
Vector<OwnPtr<GMenuItem>> m_items;
};
diff --git a/LibGUI/GMenuItem.cpp b/LibGUI/GMenuItem.cpp
index 671df2d631..e721d051a5 100644
--- a/LibGUI/GMenuItem.cpp
+++ b/LibGUI/GMenuItem.cpp
@@ -46,6 +46,8 @@ void GMenuItem::set_checked(bool checked)
void GMenuItem::update_window_server()
{
+ if (m_menu_id < 0)
+ return;
auto& action = *m_action;
WSAPI_ClientMessage request;
request.type = WSAPI_ClientMessage::Type::UpdateMenuItem;
diff --git a/LibGUI/GMenuItem.h b/LibGUI/GMenuItem.h
index e470424eef..2987528121 100644
--- a/LibGUI/GMenuItem.h
+++ b/LibGUI/GMenuItem.h
@@ -36,7 +36,7 @@ private:
void update_window_server();
Type m_type { Invalid };
- unsigned m_menu_id { 0 };
+ int m_menu_id { -1 };
unsigned m_identifier { 0 };
bool m_enabled { true };
bool m_checkable { false };