From f3fe9b64bfa81da288f87853e60ea47337915286 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 16 May 2023 16:36:39 +0100 Subject: [PATCH] GMLPlayground: Keep view_frame_action around to prevent a crash The `view_frame_action` variable only exists for the duration of `initialize_menubar()`, so calling it in `m_preview_window->on_close` would crash. This fixes that by storing the action pointer inside MainWidget. (And storing the `view_window_action` too because it felt weird storing one and not the other.) --- Userland/DevTools/GMLPlayground/MainWidget.cpp | 16 ++++++++-------- Userland/DevTools/GMLPlayground/MainWidget.h | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Userland/DevTools/GMLPlayground/MainWidget.cpp b/Userland/DevTools/GMLPlayground/MainWidget.cpp index 78392b78a1..bfff84decc 100644 --- a/Userland/DevTools/GMLPlayground/MainWidget.cpp +++ b/Userland/DevTools/GMLPlayground/MainWidget.cpp @@ -230,7 +230,7 @@ ErrorOr MainWidget::initialize_menubar(GUI::Window& window) m_views_group.set_exclusive(true); m_views_group.set_unchecking_allowed(false); - auto view_frame_action = GUI::Action::create_checkable("&Frame", [&](auto&) { + m_view_frame_action = GUI::Action::create_checkable("&Frame", [&](auto&) { dbgln("View switched to frame"); m_preview = m_preview_frame_widget; m_editor->on_change(); @@ -238,11 +238,11 @@ ErrorOr MainWidget::initialize_menubar(GUI::Window& window) m_preview_frame_widget->set_preferred_width(m_splitter->width() / 2); m_preview_frame_widget->set_visible(true); }); - view_menu->add_action(view_frame_action); - m_views_group.add_action(view_frame_action); - view_frame_action->set_checked(true); + view_menu->add_action(*m_view_frame_action); + m_views_group.add_action(*m_view_frame_action); + m_view_frame_action->set_checked(true); - auto view_window_action = GUI::Action::create_checkable("&Window", [&](auto&) { + m_view_window_action = GUI::Action::create_checkable("&Window", [&](auto&) { dbgln("View switched to window"); m_preview = m_preview_window_widget; m_editor->on_change(); @@ -250,11 +250,11 @@ ErrorOr MainWidget::initialize_menubar(GUI::Window& window) m_preview_window->show(); m_preview_frame_widget->set_visible(false); }); - view_menu->add_action(view_window_action); - m_views_group.add_action(view_window_action); + view_menu->add_action(*m_view_window_action); + m_views_group.add_action(*m_view_window_action); m_preview_window->on_close = [&] { - view_frame_action->activate(); + m_view_frame_action->activate(); }; auto help_menu = TRY(window.try_add_menu("&Help"_short_string)); diff --git a/Userland/DevTools/GMLPlayground/MainWidget.h b/Userland/DevTools/GMLPlayground/MainWidget.h index c3ae4851a2..14b85ef44f 100644 --- a/Userland/DevTools/GMLPlayground/MainWidget.h +++ b/Userland/DevTools/GMLPlayground/MainWidget.h @@ -42,7 +42,10 @@ private: RefPtr m_preview_window; RefPtr m_preview_window_widget; GUI::Widget* m_preview; + GUI::ActionGroup m_views_group; + RefPtr m_view_frame_action; + RefPtr m_view_window_action; GUI::Icon m_icon; DeprecatedString m_file_path;