summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-05-16 16:36:39 +0100
committerSam Atkins <atkinssj@gmail.com>2023-05-16 18:37:32 +0100
commitf3fe9b64bfa81da288f87853e60ea47337915286 (patch)
tree7d7f361c2b9d1f7293916422cb3b27e0826a1db2
parente9388601266770901fd2d3ff6af2e5265e5b0710 (diff)
downloadserenity-f3fe9b64bfa81da288f87853e60ea47337915286.zip
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.)
-rw-r--r--Userland/DevTools/GMLPlayground/MainWidget.cpp16
-rw-r--r--Userland/DevTools/GMLPlayground/MainWidget.h3
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<void> 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<void> 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<void> 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<GUI::Window> m_preview_window;
RefPtr<GUI::Widget> m_preview_window_widget;
GUI::Widget* m_preview;
+
GUI::ActionGroup m_views_group;
+ RefPtr<GUI::Action> m_view_frame_action;
+ RefPtr<GUI::Action> m_view_window_action;
GUI::Icon m_icon;
DeprecatedString m_file_path;