diff options
author | Sergej Reich <sergej.reich@googlemail.com> | 2013-01-26 16:30:44 +0400 |
---|---|---|
committer | Sergej Reich <sergej.reich@googlemail.com> | 2013-01-26 16:30:44 +0400 |
commit | 4245a107cf7d471322be7013855683573a9fd6ad (patch) | |
tree | 3f725a27b06809ef91c415beae4cfe3a4a9ba3de /source/blender/editors/physics/particle_edit.c | |
parent | 44060daacfe45eb97a3a8344ec12bf84e7a63ce7 (diff) |
Revert r54058, caused crash when adding paritcles in particle edit mode
MEM_recallocN() doesn't allocate memory when used on a null pointer.
Just revert commit since there is no real benefit to using
MEM_recallocN() in this case.
Diffstat (limited to 'source/blender/editors/physics/particle_edit.c')
-rw-r--r-- | source/blender/editors/physics/particle_edit.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 801b95bce25..deddc649956 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -3314,14 +3314,21 @@ static int brush_add(PEData *data, short number) int newtotpart=totpart+n; float hairmat[4][4], cur_co[3]; KDTree *tree=0; - ParticleData *pa; - PTCacheEditPoint *point; + ParticleData *pa, *new_pars = MEM_callocN(newtotpart*sizeof(ParticleData), "ParticleData new"); + PTCacheEditPoint *point, *new_points = MEM_callocN(newtotpart*sizeof(PTCacheEditPoint), "PTCacheEditPoint array new"); PTCacheEditKey *key; HairKey *hkey; + /* save existing elements */ + memcpy(new_pars, psys->particles, totpart * sizeof(ParticleData)); + memcpy(new_points, edit->points, totpart * sizeof(PTCacheEditPoint)); + /* change old arrays to new ones */ - psys->particles = MEM_recallocN(psys->particles, newtotpart * sizeof(ParticleData)); - edit->points = MEM_recallocN(edit->points, newtotpart * sizeof(PTCacheEditPoint)); + if (psys->particles) MEM_freeN(psys->particles); + psys->particles= new_pars; + + if (edit->points) MEM_freeN(edit->points); + edit->points= new_points; if (edit->mirror_cache) { MEM_freeN(edit->mirror_cache); |