From 15fb4cab15c8d57028a2f616e1b443e8dc02e4f9 Mon Sep 17 00:00:00 2001 From: Gregor Parzefall <82708541+grorp@users.noreply.github.com> Date: Thu, 11 May 2023 22:51:16 +0200 Subject: [PATCH] Fix Android segfault when game exits before TouchScreenGUI is initalized --- src/gui/touchscreengui.cpp | 13 +++++++++++++ src/gui/touchscreengui.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index c52bc59bb..5ff2f91bf 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -563,6 +563,8 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc) m_rarecontrolsbar.addButton(chat_id, L"Chat", "chat_btn.png"); m_rarecontrolsbar.addButton(inventory_id, L"inv", "inventory_btn.png"); m_rarecontrolsbar.addButton(drop_id, L"drop", "drop_btn.png"); + + m_initialized = true; } touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y) @@ -725,6 +727,8 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id) void TouchScreenGUI::translateEvent(const SEvent &event) { + if (!m_initialized) + return; if (!m_visible) { infostream << "TouchScreenGUI::translateEvent got event but not visible!" @@ -1071,6 +1075,9 @@ void TouchScreenGUI::applyJoystickStatus() TouchScreenGUI::~TouchScreenGUI() { + if (!m_initialized) + return; + for (auto &button : m_buttons) { if (button.guibutton) { button.guibutton->drop(); @@ -1096,6 +1103,9 @@ TouchScreenGUI::~TouchScreenGUI() void TouchScreenGUI::step(float dtime) { + if (!m_initialized) + return; + // simulate keyboard repeats for (auto &button : m_buttons) { if (!button.ids.empty()) { @@ -1180,6 +1190,9 @@ void TouchScreenGUI::registerHudItem(int index, const rect &rect) void TouchScreenGUI::Toggle(bool visible) { + if (!m_initialized) + return; + m_visible = visible; for (auto &button : m_buttons) { if (button.guibutton) diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h index 82d6a4a9c..267fb47a8 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchscreengui.h @@ -201,6 +201,7 @@ public: void show(); private: + bool m_initialized = false; IrrlichtDevice *m_device; IGUIEnvironment *m_guienv; IEventReceiver *m_receiver;