diff --git a/src/base_tab/AppendGameDialog.cpp b/src/base_tab/AppendGameDialog.cpp index d8fe996..a4ac126 100644 --- a/src/base_tab/AppendGameDialog.cpp +++ b/src/base_tab/AppendGameDialog.cpp @@ -17,8 +17,11 @@ AppendGameDialog::AppendGameDialog(wxWindow *parent, GameBase *base) ID_DIALOG_CANCEL_BUTTON); Bind(wxEVT_BUTTON, &AppendGameDialog::OnImport, this, ID_DIALOG_IMPORT_BUTTON); + Bind(wxEVT_CLOSE_WINDOW, &AppendGameDialog::OnClose, this); } +void AppendGameDialog::OnClose(wxCloseEvent &e) { Destroy(); } + void AppendGameDialog::OnCancel(wxCommandEvent &event) { this->Close(); } void AppendGameDialog::OnImport(wxCommandEvent &event) { diff --git a/src/base_tab/AppendGameDialog.hpp b/src/base_tab/AppendGameDialog.hpp index fba8078..648c798 100644 --- a/src/base_tab/AppendGameDialog.hpp +++ b/src/base_tab/AppendGameDialog.hpp @@ -1,11 +1,12 @@ #include "gamebase/GameBase.hpp" class AppendGameDialog : public DialogAppendGame { - GameBase *base; + GameBase *base; // Should not be destroy std::vector tinfos; public: AppendGameDialog(wxWindow *parent, GameBase *base); void OnCancel(wxCommandEvent &event); void OnImport(wxCommandEvent &event); + void OnClose(wxCloseEvent &e); }; \ No newline at end of file diff --git a/src/base_tab/BaseTab.cpp b/src/base_tab/BaseTab.cpp index 465f91f..410cc92 100644 --- a/src/base_tab/BaseTab.cpp +++ b/src/base_tab/BaseTab.cpp @@ -24,6 +24,10 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file) LoadFile(); } +BaseTab::~BaseTab() { + delete base; +} + void BaseTab::OnImport(wxCommandEvent &event) { AppendGameDialog *dia = new AppendGameDialog(this, base); dia->ShowModal(); diff --git a/src/base_tab/BaseTab.hpp b/src/base_tab/BaseTab.hpp index 5eef3b1..2f05c67 100644 --- a/src/base_tab/BaseTab.hpp +++ b/src/base_tab/BaseTab.hpp @@ -15,6 +15,7 @@ class BaseTab : public TabBase, public TabInfos { public: BaseTab(wxFrame *parent, std::string base_file); + ~BaseTab(); void ApplyPreferences(); void LoadFile(); void OnDelete(wxCommandEvent &event); diff --git a/src/base_tab/gamebase/PGNGameBase.cpp b/src/base_tab/gamebase/PGNGameBase.cpp index 7a1a6a4..edcd98f 100644 --- a/src/base_tab/gamebase/PGNGameBase.cpp +++ b/src/base_tab/gamebase/PGNGameBase.cpp @@ -6,6 +6,10 @@ PGNGameBase::PGNGameBase(std::string pgn_file) : pgn(new pgnp::PGN()) { pgn->FromFile(pgn_file); } +PGNGameBase::~PGNGameBase() { + delete pgn; // Should never fail since pgn is never NULL +} + bool PGNGameBase::NextGame() { bool game_found = false; try { diff --git a/src/base_tab/gamebase/PGNGameBase.hpp b/src/base_tab/gamebase/PGNGameBase.hpp index 982f57c..4f39e1a 100644 --- a/src/base_tab/gamebase/PGNGameBase.hpp +++ b/src/base_tab/gamebase/PGNGameBase.hpp @@ -8,6 +8,7 @@ class PGNGameBase : public GameBase { public: PGNGameBase(std::string pgn_file); + ~PGNGameBase(); Game *GetGame(std::uint32_t id); bool NextGame(); Game *GetCurrentGame(); diff --git a/src/engine_tab/EngineTab.cpp b/src/engine_tab/EngineTab.cpp index 6db6bdd..67ddc22 100644 --- a/src/engine_tab/EngineTab.cpp +++ b/src/engine_tab/EngineTab.cpp @@ -30,7 +30,7 @@ EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine, } EngineTab::EngineTab(wxWindow *parent, std::string name) - : TabEngine(parent), TabInfos(TabInfos::ENGINE) { + : TabEngine(parent), TabInfos(TabInfos::ENGINE), engine(NULL) { SetLabel(name); engineName = name; confGroup = "engines/" + engineName; @@ -44,6 +44,14 @@ EngineTab::EngineTab(wxWindow *parent, std::string name) Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON); } +EngineTab::~EngineTab() { + if (engine != NULL) { + wxLogDebug("EngineTab destructor: destroying engine!"); + engine->quit(); + delete engine; + } +} + void EngineTab::OnDelete(wxCommandEvent &event) { CONFIG_OPEN(conf); conf->DeleteGroup(confGroup); diff --git a/src/engine_tab/EngineTab.hpp b/src/engine_tab/EngineTab.hpp index b1e7ff0..aa5eb70 100644 --- a/src/engine_tab/EngineTab.hpp +++ b/src/engine_tab/EngineTab.hpp @@ -16,6 +16,7 @@ public: EngineTab(wxWindow *parent, uciadapter::UCI *engine, std::string engine_path_or_name); EngineTab(wxWindow *parent, std::string name); + ~EngineTab(); void ApplyPreferences() {} void *GetGame() { return (NULL); } void *GetBase() { return (NULL); } diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index 237a68a..4b5f3fb 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -14,6 +14,11 @@ BoardCanvas::BoardCanvas(wxFrame *parent) ApplyPreferences(); } +BoardCanvas::~BoardCanvas() { + delete t; + delete t_captures; +} + BoardCanvas::BoardCanvas(wxFrame *parent, std::uint32_t square_width, bool frozen) : BoardCanvas(parent) { diff --git a/src/game_tab/left_panel/board/BoardCanvas.hpp b/src/game_tab/left_panel/board/BoardCanvas.hpp index 34c4911..83c960a 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.hpp +++ b/src/game_tab/left_panel/board/BoardCanvas.hpp @@ -54,6 +54,7 @@ class BoardCanvas : public wxPanel { public: BoardCanvas(wxFrame *parent); BoardCanvas(wxFrame *parent,std::uint32_t square_width, bool frozen); + ~BoardCanvas(); void ApplyPreferences(); void DrawBoard(wxPaintDC &dc); void OnPaint(wxPaintEvent &event); diff --git a/src/game_tab/right_panel/LiveEngineDialog.cpp b/src/game_tab/right_panel/LiveEngineDialog.cpp index 1f509ae..73d3eb3 100644 --- a/src/game_tab/right_panel/LiveEngineDialog.cpp +++ b/src/game_tab/right_panel/LiveEngineDialog.cpp @@ -13,6 +13,13 @@ LiveEngineDialog::LiveEngineDialog(wxWindow *parent, std::string engine_name) Bind(wxEVT_CLOSE_WINDOW, &LiveEngineDialog::OnClose, this); } +LiveEngineDialog::~LiveEngineDialog() { + if (engine != NULL) { + wxLogDebug("LiveEngineDialog destructor: delete engine"); + delete engine; + } +} + void LiveEngineDialog::InitEngine() { if (engine == NULL) { wxLogDebug("Start engine: %s", engine_name); @@ -51,9 +58,8 @@ void LiveEngineDialog::OnClose(wxCloseEvent &e) { timer.Stop(); engine->stop(); engine->quit(); - delete engine; } - e.Skip(); + Destroy(); } void LiveEngineDialog::SetFEN(std::string fen) { diff --git a/src/game_tab/right_panel/LiveEngineDialog.hpp b/src/game_tab/right_panel/LiveEngineDialog.hpp index 999002f..0996ba0 100644 --- a/src/game_tab/right_panel/LiveEngineDialog.hpp +++ b/src/game_tab/right_panel/LiveEngineDialog.hpp @@ -10,6 +10,7 @@ class LiveEngineDialog : public DialogLiveEngine { public: LiveEngineDialog(wxWindow *parent, std::string engine_name); + ~LiveEngineDialog(); void InitEngine(); void TogglePauseEngine(wxCommandEvent &event); void OnTimerTick(wxTimerEvent &event);