From f9c219da93983ca0a3c5fc7e2f0579c4a44bca40 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 8 Mar 2013 20:56:54 -0500 Subject: [PATCH] a few more memory leak fixes --- src/game/GameController.cpp | 16 ++++++++++++++++ src/game/GameModel.cpp | 12 ------------ src/game/Tool.cpp | 7 ++++++- src/preview/PreviewModel.cpp | 6 ++++++ 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 1e10b0e2c..993e7689d 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -196,6 +196,22 @@ GameController::~GameController() { ui::Engine::Ref().CloseWindow(); } + //deleted here because it refuses to be deleted when deleted from gameModel even with the same code + std::deque history = gameModel->GetHistory(); + for(std::deque::iterator iter = history.begin(), end = history.end(); iter != end; ++iter) + { + delete *iter; + } + std::vector quickOptions = gameModel->GetQuickOptions(); + for(std::vector::iterator iter = quickOptions.begin(), end = quickOptions.end(); iter != end; ++iter) + { + delete *iter; + } + std::vector notifications = gameModel->GetNotifications(); + for(std::vector::iterator iter = notifications.begin(); iter != notifications.end(); ++iter) + { + delete *iter; + } delete gameModel; delete gameView; } diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 083f4bf52..e68767497 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -175,18 +175,6 @@ GameModel::~GameModel() { delete brushList[i]; } - for(std::deque::iterator iter = history.begin(), end = history.end(); iter != end; ++iter) - { - delete *iter; - } - for(std::vector::iterator iter = quickOptions.begin(), end = quickOptions.end(); iter != end; ++iter) - { - delete *iter; - } - for(std::vector::iterator iter = notifications.begin(); iter != notifications.end(); ++iter) - { - delete *iter; - } delete sim; delete ren; if(placeSave) diff --git a/src/game/Tool.cpp b/src/game/Tool.cpp index b0ad67a2d..42f9b59d2 100644 --- a/src/game/Tool.cpp +++ b/src/game/Tool.cpp @@ -19,6 +19,7 @@ Tool::Tool(int id, string name, string description, int r, int g, int b, std::st identifier(identifier) { } + VideoBuffer * Tool::GetTexture(int width, int height) { if(textureGen) @@ -35,6 +36,7 @@ std::string Tool::GetIdentifier() { return identifier; } string Tool::GetName() { return toolName; } string Tool::GetDescription() { return toolDescription; } Tool::~Tool() {} + void Tool::Click(Simulation * sim, Brush * brush, ui::Point position) { } void Tool::Draw(Simulation * sim, Brush * brush, ui::Point position) { sim->ToolBrush(position.X, position.Y, toolID, brush, strength); @@ -47,6 +49,7 @@ void Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Po } void Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {}; + ElementTool::ElementTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)): Tool(id, name, description, r, g, b, identifier, textureGen) { @@ -126,6 +129,7 @@ void GolTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) { sim->FloodParts(position.X, position.Y, PT_LIFE|(toolID<<8), -1, -1, 0); } + WindTool::WindTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)): Tool(id, name, description, r, g, b, identifier, textureGen) { @@ -163,7 +167,6 @@ void WindTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui } } void WindTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {} - void WindTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {} @@ -183,6 +186,7 @@ void Element_LIGH_Tool::Draw(Simulation * sim, Brush * brush, ui::Point position } } + Element_TESC_Tool::Element_TESC_Tool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)): ElementTool(id, name, description, r, g, b, identifier, textureGen) { @@ -204,6 +208,7 @@ void Element_TESC_Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point posi sim->FloodParts(position.X, position.Y, toolID | (radiusInfo << 8), -1, -1, 0); } + void PlopTool::Click(Simulation * sim, Brush * brush, ui::Point position) { sim->create_part(-1, position.X, position.Y, toolID); diff --git a/src/preview/PreviewModel.cpp b/src/preview/PreviewModel.cpp index dd77374e5..cb8adfd06 100644 --- a/src/preview/PreviewModel.cpp +++ b/src/preview/PreviewModel.cpp @@ -308,6 +308,12 @@ void PreviewModel::Update() PreviewModel::~PreviewModel() { if(save) delete save; + if(saveComments) + { + for(int i = 0; i < saveComments->size(); i++) + delete saveComments->at(i); + saveComments->clear(); + } saveDataBuffer.clear(); }