summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-21 13:19:10 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-21 13:19:10 (GMT)
commit8ec6aae617525d13697d1c2a612ac37be0f341d5 (patch)
treee4cdf0795e0f77505acc0c1be544532912569959 /src
parentd364a27ed6da5d75d1880c98c3fb2be683c5b915 (diff)
downloadpowder-8ec6aae617525d13697d1c2a612ac37be0f341d5.zip
powder-8ec6aae617525d13697d1c2a612ac37be0f341d5.tar.gz
Better cleanup for simulation - fix memory leaks
Diffstat (limited to 'src')
-rw-r--r--src/Graphics.cpp4
-rw-r--r--src/Graphics.h1
-rw-r--r--src/PowderToy.cpp3
-rw-r--r--src/Renderer.cpp9
-rw-r--r--src/Renderer.h1
-rw-r--r--src/client/Client.cpp1
-rw-r--r--src/game/GameController.cpp8
-rw-r--r--src/game/GameController.h5
-rw-r--r--src/game/GameModel.cpp6
-rw-r--r--src/game/GameModel.h3
-rw-r--r--src/interface/Engine.cpp6
-rw-r--r--src/search/SearchController.cpp6
-rw-r--r--src/search/SearchController.h1
-rw-r--r--src/simulation/Gravity.cpp22
-rw-r--r--src/simulation/Gravity.h1
-rw-r--r--src/simulation/Simulation.cpp10
-rw-r--r--src/simulation/Simulation.h1
17 files changed, 80 insertions, 8 deletions
diff --git a/src/Graphics.cpp b/src/Graphics.cpp
index 0aee464..ae4926a 100644
--- a/src/Graphics.cpp
+++ b/src/Graphics.cpp
@@ -2366,3 +2366,7 @@ Graphics::Graphics()
{
vid = (pixel *)malloc(PIXELSIZE * ((XRES+BARSIZE) * (YRES+MENUSIZE)));
}
+Graphics::~Graphics()
+{
+ free(vid);
+}
diff --git a/src/Graphics.h b/src/Graphics.h
index 6cd5b36..82117a7 100644
--- a/src/Graphics.h
+++ b/src/Graphics.h
@@ -167,6 +167,7 @@ public:
void ogl_blit(int x, int y, int w, int h, pixel *src, int pitch, int scale);
#endif
Graphics();
+ ~Graphics();
};
#endif
diff --git a/src/PowderToy.cpp b/src/PowderToy.cpp
index c6f5caf..f8be793 100644
--- a/src/PowderToy.cpp
+++ b/src/PowderToy.cpp
@@ -124,4 +124,7 @@ int main(int argc, char * argv[])
delta = 60.0f/fps;
}
}
+ ui::Engine::Ref().CloseWindow();
+ delete gameController;
+ delete ui::Engine::Ref().g;
}
diff --git a/src/Renderer.cpp b/src/Renderer.cpp
index 2644924..9d6076f 100644
--- a/src/Renderer.cpp
+++ b/src/Renderer.cpp
@@ -1697,3 +1697,12 @@ Renderer::Renderer(Graphics * g, Simulation * sim):
flm_data = Graphics::generate_gradient(flm_data_colours, flm_data_pos, flm_data_points, 200);
plasma_data = Graphics::generate_gradient(plasma_data_colours, plasma_data_pos, plasma_data_points, 200);
}
+
+Renderer::~Renderer()
+{
+ free(graphicscache);
+ free(flm_data);
+ free(plasma_data);
+ free(render_modes);
+ free(display_modes);
+}
diff --git a/src/Renderer.h b/src/Renderer.h
index a756f13..8592e41 100644
--- a/src/Renderer.h
+++ b/src/Renderer.h
@@ -55,6 +55,7 @@ public:
void get_sign_pos(int i, int *x0, int *y0, int *w, int *h);
void prepare_graphicscache();
Renderer(Graphics * g, Simulation * sim);
+ ~Renderer();
};
#endif
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index 9d65fda..1d450c7 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -35,6 +35,7 @@ Client::Client()
Client::~Client()
{
+ ClearThumbnailRequests();
http_done();
}
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 07f2722..d8cff8b 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -17,7 +17,13 @@ GameController::GameController()
gameView->AttachController(this);
gameModel->AddObserver(gameView);
- sim = new Simulation();
+ //sim = new Simulation();
+}
+
+GameController::~GameController()
+{
+ delete gameView;
+ delete gameModel;
}
GameView * GameController::GetView()
diff --git a/src/game/GameController.h b/src/game/GameController.h
index d9755a1..63d8e5e 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -14,11 +14,12 @@ class GameView;
class GameController
{
private:
- Simulation * sim;
+ //Simulation * sim;
GameView * gameView;
GameModel * gameModel;
public:
- GameController();
+ GameController();
+ ~GameController();
GameView * GetView();
void DrawPoints(queue<ui::Point*> & pointQueue);
void Tick();
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index 50f266f..54c8dd4 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -13,6 +13,12 @@ GameModel::GameModel():
ren = new Renderer(ui::Engine::Ref().g, sim);
}
+GameModel::~GameModel()
+{
+ delete sim;
+ delete ren;
+}
+
void GameModel::AddObserver(GameView * observer){
observers.push_back(observer);
diff --git a/src/game/GameModel.h b/src/game/GameModel.h
index 6cb74cb..c709535 100644
--- a/src/game/GameModel.h
+++ b/src/game/GameModel.h
@@ -23,7 +23,8 @@ private:
void notifySimulationChanged();
void notifyPausedChanged();
public:
- GameModel();
+ GameModel();
+ ~GameModel();
void AddObserver(GameView * observer);
int GetActiveElement();
void SetActiveElement(int element);
diff --git a/src/interface/Engine.cpp b/src/interface/Engine.cpp
index 130fc8e..6f81f56 100644
--- a/src/interface/Engine.cpp
+++ b/src/interface/Engine.cpp
@@ -27,6 +27,12 @@ Engine::~Engine()
{
if(state_ != NULL)
delete state_;
+ //Dispose of any Windows.
+ while(!windows.empty())
+ {
+ delete windows.top();
+ windows.pop();
+ }
}
void Engine::Begin(int width, int height)
diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp
index 11871fd..a9b346f 100644
--- a/src/search/SearchController.cpp
+++ b/src/search/SearchController.cpp
@@ -17,6 +17,12 @@ SearchController::SearchController()
//windowPanel.AddChild();
}
+SearchController::~SearchController()
+{
+ delete searchModel;
+ delete searchView;
+}
+
void SearchController::DoSearch(std::string query)
{
searchModel->UpdateSaveList(query);
diff --git a/src/search/SearchController.h b/src/search/SearchController.h
index 8676145..cbef93a 100644
--- a/src/search/SearchController.h
+++ b/src/search/SearchController.h
@@ -13,6 +13,7 @@ private:
SearchView * searchView;
public:
SearchController();
+ ~SearchController();
SearchView * GetView() { return searchView; }
void DoSearch(std::string query);
};
diff --git a/src/simulation/Gravity.cpp b/src/simulation/Gravity.cpp
index cc20b2f..43ca8e6 100644
--- a/src/simulation/Gravity.cpp
+++ b/src/simulation/Gravity.cpp
@@ -48,6 +48,9 @@ void Gravity::gravity_init()
gravx = (float *)calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
gravp = (float *)calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
gravmask = (unsigned int *)calloc((XRES/CELL)*(YRES/CELL), sizeof(unsigned));
+#ifdef GRAVFFT
+ grav_fft_init();
+#endif
}
void Gravity::gravity_cleanup()
@@ -55,6 +58,17 @@ void Gravity::gravity_cleanup()
#ifdef GRAVFFT
grav_fft_cleanup();
#endif
+ //Free gravity info
+ free(th_ogravmap);
+ free(th_gravmap);
+ free(th_gravy);
+ free(th_gravx);
+ free(th_gravp);
+ free(gravmap);
+ free(gravy);
+ free(gravx);
+ free(gravp);
+ free(gravmask);
}
void Gravity::gravity_update_async()
@@ -124,9 +138,6 @@ void Gravity::update_grav_async()
//memset(th_gravy, 0, XRES*YRES*sizeof(float));
//memset(th_gravx, 0, XRES*YRES*sizeof(float));
//memset(th_gravp, 0, XRES*YRES*sizeof(float));
-#ifdef GRAVFFT
- grav_fft_init();
-#endif
while(!thread_done){
if(!done){
update_grav();
@@ -486,3 +497,8 @@ Gravity::Gravity()
{
gravity_init();
}
+
+Gravity::~Gravity()
+{
+ gravity_cleanup();
+}
diff --git a/src/simulation/Gravity.h b/src/simulation/Gravity.h
index 9f36240..72b387d 100644
--- a/src/simulation/Gravity.h
+++ b/src/simulation/Gravity.h
@@ -86,6 +86,7 @@ public:
#endif
Gravity();
+ ~Gravity();
};
/*extern int ngrav_enable; //Newtonian gravity
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index f7dec79..7ee0391 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -3197,7 +3197,15 @@ void Simulation::update_particles()//doesn't update the particles themselves, bu
*/
}
-Simulation::Simulation()
+Simulation::~Simulation()
+{
+ free(signs);
+ delete grav;
+ delete air;
+}
+
+Simulation::Simulation():
+ sys_pause(0)
{
//Create and attach gravity simulation
grav = new Gravity();
diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h
index 969b030..f6fd1b0 100644
--- a/src/simulation/Simulation.h
+++ b/src/simulation/Simulation.h
@@ -235,6 +235,7 @@ public:
void clear_sim();
void UpdateParticles();
Simulation();
+ ~Simulation();
};
//#endif