summaryrefslogtreecommitdiff
path: root/src/simulation
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/simulation
parentd364a27ed6da5d75d1880c98c3fb2be683c5b915 (diff)
downloadpowder-8ec6aae617525d13697d1c2a612ac37be0f341d5.zip
powder-8ec6aae617525d13697d1c2a612ac37be0f341d5.tar.gz
Better cleanup for simulation - fix memory leaks
Diffstat (limited to 'src/simulation')
-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
4 files changed, 30 insertions, 4 deletions
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