mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
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
This commit is contained in:
parent
ebf645d72a
commit
9823354754
Notes:
sideshowbarker
2024-07-19 13:58:34 +09:00
Author: https://github.com/alexispurslane Commit: https://github.com/SerenityOS/serenity/commit/98233547541 Pull-request: https://github.com/SerenityOS/serenity/pull/83 Reviewed-by: https://github.com/awesomekling
4 changed files with 7 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Add table
Reference in a new issue