Bug fix: memoryleak when using smoke heat/velocity data as texture

* In addition to fixing the memleak it's much better to always copy the voxeldata to the texture. Smoke data can change at any time due to some changes, so we can't depend on that data.
* Thanks to MiikaH for finding this!
This commit is contained in:
Janne Karhu 2010-11-11 17:03:09 +00:00
parent 4d9684ebdf
commit 1659e3fca7
2 changed files with 13 additions and 6 deletions

@ -1286,8 +1286,7 @@ void BKE_free_pointdensity(PointDensity *pd)
void BKE_free_voxeldatadata(struct VoxelData *vd)
{
if (vd->dataset) {
if(vd->file_format != TEX_VD_SMOKE)
MEM_freeN(vd->dataset);
MEM_freeN(vd->dataset);
vd->dataset = NULL;
}

@ -238,13 +238,22 @@ static void init_frame_smoke(VoxelData *vd)
}
else {
int totRes;
float *density;
if (smd->domain->flags & MOD_SMOKE_HIGHRES) {
smoke_turbulence_get_res(smd->domain->wt, vd->resol);
vd->dataset = smoke_turbulence_get_density(smd->domain->wt);
density = smoke_turbulence_get_density(smd->domain->wt);
} else {
VECCOPY(vd->resol, smd->domain->res);
vd->dataset = smoke_get_density(smd->domain->fluid);
density = smoke_get_density(smd->domain->fluid);
}
totRes = (vd->resol[0])*(vd->resol[1])*(vd->resol[2]);
/* always store copy, as smoke internal data can change */
vd->dataset = MEM_mapallocN(sizeof(float)*(totRes), "smoke data");
memcpy(vd->dataset, density, sizeof(float)*totRes);
} // end of fluid condition
}
}
@ -267,8 +276,7 @@ static void cache_voxeldata(struct Render *re,Tex *tex)
/* clear out old cache, ready for new */
if (vd->dataset) {
if(vd->file_format != TEX_VD_SMOKE)
MEM_freeN(vd->dataset);
MEM_freeN(vd->dataset);
vd->dataset = NULL;
}