From 145dd7095cb3c462ccaebae41a1a0b0932ae6907 Mon Sep 17 00:00:00 2001 From: Joey Pollack Date: Fri, 11 Feb 2022 12:56:22 -0500 Subject: [PATCH] Fixed crash in editor mode (log listener not being removed because destructors not being called. Base class destructors MUST be virtual!) --- src/core/core.cpp | 1 + src/core/core_console.cpp | 10 ++++++++-- src/core/core_console.h | 1 + src/internal_libs/gui/console.cpp | 13 +++++++++++-- src/internal_libs/gui/console.h | 2 ++ src/internal_libs/gui/panel.cpp | 5 +++++ src/internal_libs/gui/panel.h | 1 + src/run_modes/editor/panels/worldView.cpp | 2 +- test_data/engine_state.xml | 2 +- 9 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index 68af891..6a9de6a 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -246,6 +246,7 @@ namespace lunarium return; #else mpRunMode = new editor::Editor; + delete mPanels[gui::PanelType::PT_CORE_CONSOLE]; mPanels[gui::PanelType::PT_CORE_CONSOLE] = nullptr; // Editor has it's own console diff --git a/src/core/core_console.cpp b/src/core/core_console.cpp index 5a7c772..ebdc8b9 100644 --- a/src/core/core_console.cpp +++ b/src/core/core_console.cpp @@ -10,13 +10,19 @@ #include #include // To use the DockWindowXXX methods +#include + namespace lunarium { CoreConsole::CoreConsole() : Console(gui::PanelType::PT_CORE_CONSOLE, "Core Console"), mDockIsInit(false) - { + { - } + } + + CoreConsole::~CoreConsole() + { + } bool CoreConsole::DoFrame() { diff --git a/src/core/core_console.h b/src/core/core_console.h index 8b7148b..a9312d3 100644 --- a/src/core/core_console.h +++ b/src/core/core_console.h @@ -17,6 +17,7 @@ namespace lunarium { public: CoreConsole(); + virtual ~CoreConsole(); bool DoFrame() override; private: diff --git a/src/internal_libs/gui/console.cpp b/src/internal_libs/gui/console.cpp index 5b3a119..e6f3247 100644 --- a/src/internal_libs/gui/console.cpp +++ b/src/internal_libs/gui/console.cpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace lunarium { namespace gui @@ -47,12 +48,20 @@ namespace lunarium Console::Console(PanelType type, const char* name) : Panel(type, name, gui::PanelDockZone::DDZ_NONE, false), mbNewCommand(false), mRecalledCommand(-1), mIsFocused(false), mListener(nullptr), - mbOglDebug(false), mbInfoVerbose(false) + mbOglDebug(false), mbInfoVerbose(false), mpListener(nullptr) { memset(mBuffer, 0, LUA_CON_BUFFER_SIZE); - Logger::GetInstance()->AddListener(new GuiListener(this)); + mpListener = Logger::GetInstance()->AddListener(new GuiListener(this)); } + Console::~Console() + { + Logger::GetInstance()->RemoveListener(mpListener); + delete mpListener; + mpListener = nullptr; + } + + bool Console::IsFocused() const { return mIsFocused; diff --git a/src/internal_libs/gui/console.h b/src/internal_libs/gui/console.h index 302010d..0b50063 100644 --- a/src/internal_libs/gui/console.h +++ b/src/internal_libs/gui/console.h @@ -35,6 +35,7 @@ namespace lunarium { public: Console(PanelType type, const char* name); + virtual ~Console(); virtual void Update(float dt); virtual bool DoFrame(); @@ -49,6 +50,7 @@ namespace lunarium private: // LUA COMMAND STUFF + LogListener* mpListener; char mBuffer[LUA_CON_BUFFER_SIZE]; std::vector mCommandHistory; bool mbNewCommand; diff --git a/src/internal_libs/gui/panel.cpp b/src/internal_libs/gui/panel.cpp index 97626f9..1a061b2 100644 --- a/src/internal_libs/gui/panel.cpp +++ b/src/internal_libs/gui/panel.cpp @@ -20,6 +20,11 @@ namespace gui } + Panel::~Panel() + { + + } + PanelType Panel::GetType() const { return mType; diff --git a/src/internal_libs/gui/panel.h b/src/internal_libs/gui/panel.h index 5e60ba9..d1f1d5c 100644 --- a/src/internal_libs/gui/panel.h +++ b/src/internal_libs/gui/panel.h @@ -23,6 +23,7 @@ namespace gui { public: Panel(PanelType type, std::string name, PanelDockZone dock_zone, bool isOpen = false); + virtual ~Panel(); PanelType GetType() const; const char* GetName() const; diff --git a/src/run_modes/editor/panels/worldView.cpp b/src/run_modes/editor/panels/worldView.cpp index 87a8d8d..858f5ed 100644 --- a/src/run_modes/editor/panels/worldView.cpp +++ b/src/run_modes/editor/panels/worldView.cpp @@ -7,7 +7,7 @@ ******************************************************************************/ #include "worldView.h" -#include +#include #include #include #include diff --git a/test_data/engine_state.xml b/test_data/engine_state.xml index 5cf7851..277eb02 100644 --- a/test_data/engine_state.xml +++ b/test_data/engine_state.xml @@ -1,6 +1,6 @@ data/ - +