From 582bf1eaf36a7bcebc4c2ba551227c2f12a4c3a5 Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Tue, 30 Jan 2024 21:54:20 +0100 Subject: [PATCH] Run: Fix bug where it would crash because uninitialized main widget The set_main_widget() function only calls the construct and not `try_create()` that the GMLCompiler generates so all calls to `find_descendant_of_type_named()` would result in null pointers that would resolve in a crash. --- Userland/Applications/Run/RunWindow.cpp | 9 +++++++-- Userland/Applications/Run/RunWindow.h | 4 ++++ Userland/Applications/Run/main.cpp | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/Run/RunWindow.cpp b/Userland/Applications/Run/RunWindow.cpp index ede98ed43d..459cd21889 100644 --- a/Userland/Applications/Run/RunWindow.cpp +++ b/Userland/Applications/Run/RunWindow.cpp @@ -26,6 +26,8 @@ #include #include +namespace Run { + RunWindow::RunWindow() : m_path_history() , m_path_history_model(GUI::ItemListModel::create(m_path_history)) @@ -41,7 +43,8 @@ RunWindow::RunWindow() set_resizable(false); set_minimizable(false); - auto main_widget = set_main_widget(); + auto main_widget = MUST(Run::MainWidget::try_create()); + set_main_widget(main_widget); m_icon_image_widget = *main_widget->find_descendant_of_type_named("icon"); m_icon_image_widget->set_bitmap(app_icon.bitmap_for_size(32)); @@ -62,7 +65,7 @@ RunWindow::RunWindow() close(); }; - m_browse_button = *find_descendant_of_type_named("browse_button"); + m_browse_button = *main_widget->find_descendant_of_type_named("browse_button"); m_browse_button->on_click = [this](auto) { Optional path = GUI::FilePicker::get_open_filepath(this, {}, Core::StandardPaths::home_directory(), false, GUI::Dialog::ScreenPosition::Center); if (path.has_value()) @@ -189,3 +192,5 @@ ErrorOr RunWindow::save_history() return {}; } + +} diff --git a/Userland/Applications/Run/RunWindow.h b/Userland/Applications/Run/RunWindow.h index 9c3076ce1b..fd37dded87 100644 --- a/Userland/Applications/Run/RunWindow.h +++ b/Userland/Applications/Run/RunWindow.h @@ -13,6 +13,8 @@ #include #include +namespace Run { + class RunWindow final : public GUI::Window { C_OBJECT(RunWindow) public: @@ -40,3 +42,5 @@ private: RefPtr m_browse_button; RefPtr m_path_combo_box; }; + +} diff --git a/Userland/Applications/Run/main.cpp b/Userland/Applications/Run/main.cpp index 78be277667..cf0cae0cf1 100644 --- a/Userland/Applications/Run/main.cpp +++ b/Userland/Applications/Run/main.cpp @@ -15,7 +15,7 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::pledge("stdio recvfd sendfd thread cpath rpath wpath unix proc exec")); auto app = TRY(GUI::Application::create(arguments)); - auto window = TRY(RunWindow::try_create()); + auto window = TRY(Run::RunWindow::try_create()); constexpr int margin = 16; window->move_to(margin, GUI::Desktop::the().rect().bottom() - 1 - GUI::Desktop::the().taskbar_height() - margin - window->height());