mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Fix majors memory leaks (TODO: shared_ptr for Game objects and implement ~Game())
This commit is contained in:
parent
8f1e8fa106
commit
a8c59c41bc
12 changed files with 40 additions and 4 deletions
|
@ -17,8 +17,11 @@ AppendGameDialog::AppendGameDialog(wxWindow *parent, GameBase *base)
|
||||||
ID_DIALOG_CANCEL_BUTTON);
|
ID_DIALOG_CANCEL_BUTTON);
|
||||||
Bind(wxEVT_BUTTON, &AppendGameDialog::OnImport, this,
|
Bind(wxEVT_BUTTON, &AppendGameDialog::OnImport, this,
|
||||||
ID_DIALOG_IMPORT_BUTTON);
|
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::OnCancel(wxCommandEvent &event) { this->Close(); }
|
||||||
|
|
||||||
void AppendGameDialog::OnImport(wxCommandEvent &event) {
|
void AppendGameDialog::OnImport(wxCommandEvent &event) {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#include "gamebase/GameBase.hpp"
|
#include "gamebase/GameBase.hpp"
|
||||||
|
|
||||||
class AppendGameDialog : public DialogAppendGame {
|
class AppendGameDialog : public DialogAppendGame {
|
||||||
GameBase *base;
|
GameBase *base; // Should not be destroy
|
||||||
std::vector<TabInfos *> tinfos;
|
std::vector<TabInfos *> tinfos;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AppendGameDialog(wxWindow *parent, GameBase *base);
|
AppendGameDialog(wxWindow *parent, GameBase *base);
|
||||||
void OnCancel(wxCommandEvent &event);
|
void OnCancel(wxCommandEvent &event);
|
||||||
void OnImport(wxCommandEvent &event);
|
void OnImport(wxCommandEvent &event);
|
||||||
|
void OnClose(wxCloseEvent &e);
|
||||||
};
|
};
|
|
@ -24,6 +24,10 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file)
|
||||||
LoadFile();
|
LoadFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BaseTab::~BaseTab() {
|
||||||
|
delete base;
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTab::OnImport(wxCommandEvent &event) {
|
void BaseTab::OnImport(wxCommandEvent &event) {
|
||||||
AppendGameDialog *dia = new AppendGameDialog(this, base);
|
AppendGameDialog *dia = new AppendGameDialog(this, base);
|
||||||
dia->ShowModal();
|
dia->ShowModal();
|
||||||
|
|
|
@ -15,6 +15,7 @@ class BaseTab : public TabBase, public TabInfos {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BaseTab(wxFrame *parent, std::string base_file);
|
BaseTab(wxFrame *parent, std::string base_file);
|
||||||
|
~BaseTab();
|
||||||
void ApplyPreferences();
|
void ApplyPreferences();
|
||||||
void LoadFile();
|
void LoadFile();
|
||||||
void OnDelete(wxCommandEvent &event);
|
void OnDelete(wxCommandEvent &event);
|
||||||
|
|
|
@ -6,6 +6,10 @@ PGNGameBase::PGNGameBase(std::string pgn_file) : pgn(new pgnp::PGN()) {
|
||||||
pgn->FromFile(pgn_file);
|
pgn->FromFile(pgn_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PGNGameBase::~PGNGameBase() {
|
||||||
|
delete pgn; // Should never fail since pgn is never NULL
|
||||||
|
}
|
||||||
|
|
||||||
bool PGNGameBase::NextGame() {
|
bool PGNGameBase::NextGame() {
|
||||||
bool game_found = false;
|
bool game_found = false;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -8,6 +8,7 @@ class PGNGameBase : public GameBase {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PGNGameBase(std::string pgn_file);
|
PGNGameBase(std::string pgn_file);
|
||||||
|
~PGNGameBase();
|
||||||
Game *GetGame(std::uint32_t id);
|
Game *GetGame(std::uint32_t id);
|
||||||
bool NextGame();
|
bool NextGame();
|
||||||
Game *GetCurrentGame();
|
Game *GetCurrentGame();
|
||||||
|
|
|
@ -30,7 +30,7 @@ EngineTab::EngineTab(wxWindow *parent, uciadapter::UCI *engine,
|
||||||
}
|
}
|
||||||
|
|
||||||
EngineTab::EngineTab(wxWindow *parent, std::string name)
|
EngineTab::EngineTab(wxWindow *parent, std::string name)
|
||||||
: TabEngine(parent), TabInfos(TabInfos::ENGINE) {
|
: TabEngine(parent), TabInfos(TabInfos::ENGINE), engine(NULL) {
|
||||||
SetLabel(name);
|
SetLabel(name);
|
||||||
engineName = name;
|
engineName = name;
|
||||||
confGroup = "engines/" + engineName;
|
confGroup = "engines/" + engineName;
|
||||||
|
@ -44,6 +44,14 @@ EngineTab::EngineTab(wxWindow *parent, std::string name)
|
||||||
Bind(wxEVT_BUTTON, &EngineTab::OnDelete, this, ENGINE_DELETE_CONF_BUTTON);
|
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) {
|
void EngineTab::OnDelete(wxCommandEvent &event) {
|
||||||
CONFIG_OPEN(conf);
|
CONFIG_OPEN(conf);
|
||||||
conf->DeleteGroup(confGroup);
|
conf->DeleteGroup(confGroup);
|
||||||
|
|
|
@ -16,6 +16,7 @@ public:
|
||||||
EngineTab(wxWindow *parent, uciadapter::UCI *engine,
|
EngineTab(wxWindow *parent, uciadapter::UCI *engine,
|
||||||
std::string engine_path_or_name);
|
std::string engine_path_or_name);
|
||||||
EngineTab(wxWindow *parent, std::string name);
|
EngineTab(wxWindow *parent, std::string name);
|
||||||
|
~EngineTab();
|
||||||
void ApplyPreferences() {}
|
void ApplyPreferences() {}
|
||||||
void *GetGame() { return (NULL); }
|
void *GetGame() { return (NULL); }
|
||||||
void *GetBase() { return (NULL); }
|
void *GetBase() { return (NULL); }
|
||||||
|
|
|
@ -14,6 +14,11 @@ BoardCanvas::BoardCanvas(wxFrame *parent)
|
||||||
ApplyPreferences();
|
ApplyPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BoardCanvas::~BoardCanvas() {
|
||||||
|
delete t;
|
||||||
|
delete t_captures;
|
||||||
|
}
|
||||||
|
|
||||||
BoardCanvas::BoardCanvas(wxFrame *parent, std::uint32_t square_width,
|
BoardCanvas::BoardCanvas(wxFrame *parent, std::uint32_t square_width,
|
||||||
bool frozen)
|
bool frozen)
|
||||||
: BoardCanvas(parent) {
|
: BoardCanvas(parent) {
|
||||||
|
|
|
@ -54,6 +54,7 @@ class BoardCanvas : public wxPanel {
|
||||||
public:
|
public:
|
||||||
BoardCanvas(wxFrame *parent);
|
BoardCanvas(wxFrame *parent);
|
||||||
BoardCanvas(wxFrame *parent,std::uint32_t square_width, bool frozen);
|
BoardCanvas(wxFrame *parent,std::uint32_t square_width, bool frozen);
|
||||||
|
~BoardCanvas();
|
||||||
void ApplyPreferences();
|
void ApplyPreferences();
|
||||||
void DrawBoard(wxPaintDC &dc);
|
void DrawBoard(wxPaintDC &dc);
|
||||||
void OnPaint(wxPaintEvent &event);
|
void OnPaint(wxPaintEvent &event);
|
||||||
|
|
|
@ -13,6 +13,13 @@ LiveEngineDialog::LiveEngineDialog(wxWindow *parent, std::string engine_name)
|
||||||
Bind(wxEVT_CLOSE_WINDOW, &LiveEngineDialog::OnClose, this);
|
Bind(wxEVT_CLOSE_WINDOW, &LiveEngineDialog::OnClose, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LiveEngineDialog::~LiveEngineDialog() {
|
||||||
|
if (engine != NULL) {
|
||||||
|
wxLogDebug("LiveEngineDialog destructor: delete engine");
|
||||||
|
delete engine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LiveEngineDialog::InitEngine() {
|
void LiveEngineDialog::InitEngine() {
|
||||||
if (engine == NULL) {
|
if (engine == NULL) {
|
||||||
wxLogDebug("Start engine: %s", engine_name);
|
wxLogDebug("Start engine: %s", engine_name);
|
||||||
|
@ -51,9 +58,8 @@ void LiveEngineDialog::OnClose(wxCloseEvent &e) {
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
engine->stop();
|
engine->stop();
|
||||||
engine->quit();
|
engine->quit();
|
||||||
delete engine;
|
|
||||||
}
|
}
|
||||||
e.Skip();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiveEngineDialog::SetFEN(std::string fen) {
|
void LiveEngineDialog::SetFEN(std::string fen) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ class LiveEngineDialog : public DialogLiveEngine {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LiveEngineDialog(wxWindow *parent, std::string engine_name);
|
LiveEngineDialog(wxWindow *parent, std::string engine_name);
|
||||||
|
~LiveEngineDialog();
|
||||||
void InitEngine();
|
void InitEngine();
|
||||||
void TogglePauseEngine(wxCommandEvent &event);
|
void TogglePauseEngine(wxCommandEvent &event);
|
||||||
void OnTimerTick(wxTimerEvent &event);
|
void OnTimerTick(wxTimerEvent &event);
|
||||||
|
|
Loading…
Add table
Reference in a new issue