diff --git a/src/Graphics.cpp b/src/Graphics.cpp index 0aee46491..ae4926a6a 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 6cd5b3602..82117a70a 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 c6f5caffa..f8be79387 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 2644924f0..9d6076fa2 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 a756f13f4..8592e41e1 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 9d65fda47..1d450c7c0 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 07f2722a1..d8cff8bf9 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 d9755a1b6..63d8e5e5b 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 & pointQueue); void Tick(); diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 50f266fa4..54c8dd48b 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 6cb74cb61..c70953570 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 130fc8e19..6f81f5648 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 11871fd1c..a9b346faa 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 8676145a0..cbef93ac2 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 cc20b2fa8..43ca8e648 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 9f36240ee..72b387d92 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 f7dec7998..7ee039154 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 969b0307e..f6fd1b0cc 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -235,6 +235,7 @@ public: void clear_sim(); void UpdateParticles(); Simulation(); + ~Simulation(); }; //#endif