aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-02-28 19:13:27 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-02-28 19:13:27 +0100
commit4c959fe12ed2f26cbfac9646d3488cb00676fb31 (patch)
tree551c288b6041ad7e60bcfab0ebffed1e6f300c62 /src
parenta8c59c41bc103f0336d9982369be5dd85ac68111 (diff)
Improve Game and HalfMoves memory management
Diffstat (limited to 'src')
-rw-r--r--src/game_tab/Game.cpp8
-rw-r--r--src/game_tab/Game.hpp2
-rw-r--r--src/game_tab/GameTab.cpp4
-rw-r--r--src/game_tab/GameTab.hpp2
-rw-r--r--src/game_tab/HalfMove.cpp5
-rw-r--r--src/ochess.hpp1
6 files changed, 19 insertions, 3 deletions
diff --git a/src/game_tab/Game.cpp b/src/game_tab/Game.cpp
index e26efd7..8b52ca6 100644
--- a/src/game_tab/Game.cpp
+++ b/src/game_tab/Game.cpp
@@ -15,13 +15,19 @@ Game::Game(std::string fen) : current(NULL), moves(NULL), result("*") {
board = chessarbiter::FENParser::Parse(fen).board;
}
-Game::Game(HalfMove *m, std::string initial_fen): result("*") {
+Game::Game(HalfMove *m, std::string initial_fen) : result("*") {
moves = m;
current = m;
this->initial_fen = initial_fen;
board = chessarbiter::FENParser::Parse(initial_fen).board;
}
+Game::~Game() {
+ if (moves != NULL) {
+ delete moves;
+ }
+}
+
std::string Game::GetBoard() { return (board); }
std::string Game::GetTag(std::string tagname) { return (tags[tagname]); }
diff --git a/src/game_tab/Game.hpp b/src/game_tab/Game.hpp
index 53249fb..f0414c8 100644
--- a/src/game_tab/Game.hpp
+++ b/src/game_tab/Game.hpp
@@ -18,7 +18,7 @@ public:
Game();
Game(std::string fen);
Game(HalfMove *m, std::string initial_fen);
-
+ ~Game();
std::string GetBoard();
std::string GetTag(std::string tagname);
void SetTag(std::string tagname, std::string value);
diff --git a/src/game_tab/GameTab.cpp b/src/game_tab/GameTab.cpp
index c3aceb8..769681c 100644
--- a/src/game_tab/GameTab.cpp
+++ b/src/game_tab/GameTab.cpp
@@ -30,6 +30,10 @@ GameTab::GameTab(wxFrame *parent, Game *game)
Bind(GAME_CHANGE, &GameTab::OnGameChange, this, wxID_ANY);
}
+GameTab::~GameTab() {
+ delete game;
+}
+
void GameTab::OnGameChange(wxCommandEvent &event) {
board_panel->Notify();
editor_panel->Notify();
diff --git a/src/game_tab/GameTab.hpp b/src/game_tab/GameTab.hpp
index c9dcd5a..15f0514 100644
--- a/src/game_tab/GameTab.hpp
+++ b/src/game_tab/GameTab.hpp
@@ -17,12 +17,14 @@ class GameTab : public wxPanel, public TabInfos {
GameTabRightPanel *editor_panel;
GameTabLeftPanel *board_panel;
Game *game;
+
void RefreshLabel();
void OnRefreshTabTitle(wxCommandEvent &event);
void OnGameChange(wxCommandEvent &event);
public:
GameTab(wxFrame *parent, Game *game);
+ ~GameTab();
void ApplyPreferences();
void *GetGame() { return (game); }
void *GetBase() { return (NULL); };
diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp
index f43b7f2..e366004 100644
--- a/src/game_tab/HalfMove.cpp
+++ b/src/game_tab/HalfMove.cpp
@@ -10,6 +10,9 @@ HalfMove::HalfMove(std::string move, std::string fen) : fen(fen), capture(' ') {
}
HalfMove::~HalfMove() {
+ if (mainline != NULL) {
+ delete mainline;
+ }
for (HalfMove *m : variations) {
delete m;
}
@@ -221,7 +224,7 @@ void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) {
BuildAndVerify(m->mainline, arbiter.GetFEN());
}
for (HalfMove *v : m->variations) {
- BuildAndVerify(v,fen);
+ BuildAndVerify(v, fen);
}
}
void HalfMove::BuildAndVerify(std::string initial_fen) {
diff --git a/src/ochess.hpp b/src/ochess.hpp
index e413071..6303e31 100644
--- a/src/ochess.hpp
+++ b/src/ochess.hpp
@@ -11,6 +11,7 @@
#include <wx/filefn.h> // Check file exists etc
#include <wx/log.h>
#include "gui.h"
+#include <memory>
#define MAINWIN ((MainWindow *)wxGetApp().GetTopWindow())