diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_subsurf.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 9 |
2 files changed, 8 insertions, 3 deletions
diff --git a/source/blender/blenkernel/BKE_subsurf.h b/source/blender/blenkernel/BKE_subsurf.h index f52bb2ab9cb..92170325113 100644 --- a/source/blender/blenkernel/BKE_subsurf.h +++ b/source/blender/blenkernel/BKE_subsurf.h @@ -125,6 +125,8 @@ typedef struct CCGDerivedMesh { struct CCGFace **gridFaces; struct DMFlagMat *gridFlagMats; unsigned int **gridHidden; + /* Elements in arrays above. */ + unsigned int numGrid; struct { struct MultiresModifierData *mmd; diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 0cdc97c829f..f8025f8df84 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -4031,10 +4031,12 @@ static void ccgDM_release(DerivedMesh *dm) if (ccgdm->gridOffset) MEM_freeN(ccgdm->gridOffset); if (ccgdm->gridFlagMats) MEM_freeN(ccgdm->gridFlagMats); if (ccgdm->gridHidden) { - int i, numGrids = dm->getNumGrids(dm); - for (i = 0; i < numGrids; i++) { - if (ccgdm->gridHidden[i]) + /* Using dm->getNumGrids(dm) accesses freed memory */ + uint numGrids = ccgdm->numGrid; + for (uint i = 0; i < numGrids; i++) { + if (ccgdm->gridHidden[i]) { MEM_freeN(ccgdm->gridHidden[i]); + } } MEM_freeN(ccgdm->gridHidden); } @@ -4338,6 +4340,7 @@ static void ccgdm_create_grids(DerivedMesh *dm) ccgdm->gridFaces = gridFaces; ccgdm->gridOffset = gridOffset; ccgdm->gridFlagMats = gridFlagMats; + ccgdm->numGrid = numGrids; } static CCGElem **ccgDM_getGridData(DerivedMesh *dm) |