diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-12 14:28:39 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-12 14:28:39 +0100 |
commit | 627e06632a8d17508a486f41f97a7a7e567eea60 (patch) | |
tree | 4eb1bb94d9cfcf4430de3fd9ff89e97728c92ea8 /WindowServer | |
parent | 3085e400bcda710ac6977016768581bc789bb937 (diff) | |
download | serenity-627e06632a8d17508a486f41f97a7a7e567eea60.zip |
WindowServer: Don't crash when trying to open an empty menu.
Diffstat (limited to 'WindowServer')
-rw-r--r-- | WindowServer/WSMenu.h | 1 | ||||
-rw-r--r-- | WindowServer/WSWindowManager.cpp | 8 |
2 files changed, 6 insertions, 3 deletions
diff --git a/WindowServer/WSMenu.h b/WindowServer/WSMenu.h index 24a03587f0..bd15d02e59 100644 --- a/WindowServer/WSMenu.h +++ b/WindowServer/WSMenu.h @@ -23,6 +23,7 @@ public: WSMenuBar* menu_bar() { return m_menubar; } const WSMenuBar* menu_bar() const { return m_menubar; } + bool is_empty() const { return m_items.is_empty(); } int item_count() const { return m_items.size(); } WSMenuItem* item(int i) { return m_items[i].ptr(); } const WSMenuItem* item(int i) const { return m_items[i].ptr(); } diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index 00da34f522..1fb86b8657 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -387,9 +387,11 @@ void WSWindowManager::handle_menu_mouse_event(WSMenu& menu, WSMouseEvent& event) if (m_current_menu == &menu) return; close_current_menu(); - auto& menu_window = menu.ensure_menu_window(); - menu_window.move_to({ menu.rect_in_menubar().x(), menu.rect_in_menubar().bottom() }); - menu_window.set_visible(true); + if (!menu.is_empty()) { + auto& menu_window = menu.ensure_menu_window(); + menu_window.move_to({ menu.rect_in_menubar().x(), menu.rect_in_menubar().bottom() }); + menu_window.set_visible(true); + } m_current_menu = &menu; return; } |