diff options
author | over0219 <over0219@umn.edu> | 2020-06-22 22:26:23 +0300 |
---|---|---|
committer | over0219 <over0219@umn.edu> | 2020-06-22 22:26:23 +0300 |
commit | c214acce20b6066dd8b0f70dfa16a597059358a6 (patch) | |
tree | 34a48d8e1ad91a9be0b80e0b80f2c263528ac4c3 /source | |
parent | 688643c9fdf19802fe7c3bb4e6b53754fa9e7cca (diff) |
fixed issue with rand causing mem error
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/softbody.c | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 5d94e9014f3..d97b76ba1e3 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -3580,7 +3580,7 @@ static void init_admmpd_interface(Object *ob, float (*vertexCos)[3]) MEM_freeN(sb->admmpd); sb->admmpd = NULL; } - sb->admmpd = (ADMMPDInterfaceData*)MEM_callocN(sizeof(ADMMPDInterfaceData), "SoftBody_ADMMPD"); + sb->admmpd = MEM_callocN(sizeof(ADMMPDInterfaceData), "SoftBody_ADMMPD"); // Resize data int totfaces = poly_to_tri_count(me->totpoly, me->totloop); @@ -3616,7 +3616,7 @@ static void init_admmpd_interface(Object *ob, float (*vertexCos)[3]) looptri = NULL; // Initalize solver and free tmp data - sb->admmpd->init_mode = 1; + sb->admmpd->init_mode = 1; // 0=tetmesh, 1=lattice admmpd_init(sb->admmpd, in_verts, in_faces); MEM_freeN(in_verts); MEM_freeN(in_faces); @@ -3630,9 +3630,12 @@ static void init_admmpd_interface(Object *ob, float (*vertexCos)[3]) } sb->totpoint = sb->admmpd->totverts; sb->totspring = 0; - sb->bpoint = MEM_callocN(sb->totpoint * sizeof(BodyPoint), "bodypoint"); + sb->bpoint = (BodyPoint*)MEM_callocN(sb->totpoint*sizeof(BodyPoint), "bodypoint"); } + // admmpd_init will have created tets with extra vertices besides + // the ones on the surface (vertexCos). We'll store those vertices + // in SoftBody::bpoint. admmpd_copy_to_bodypoint_and_object(sb->admmpd,sb->bpoint,NULL); } @@ -3660,25 +3663,17 @@ void sbObjectStep_admmpd( float timescale = 0.f; BKE_ptcache_id_from_softbody(&pid, ob, sb); BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, ×cale); - - // BKE_ptcache_validate: - // sets flag that simulation is valid (|=) - // and sets simframe to framenr - // Calling BKE_ptcache_id_reset calls - // free_softbody_intern - // Reset cache - if (sb->admmpd == NULL || - sb->admmpd->mesh_totverts != numVerts) - { - cache->flag |= PTCACHE_OUTDATED; - BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); - BKE_ptcache_validate(cache, 0); - cache->last_exact = 0; - cache->flag &= ~PTCACHE_REDO_NEEDED; + // check for changes in mesh, should only happen in case the mesh + // structure changes during an animation. + // Hopefully we're short-circuiting the boolean here. + if (sb->admmpd != NULL && + sb->admmpd->mesh_totverts != numVerts) { + BKE_ptcache_invalidate(cache); + return; } - // Clamp simulation frame + // clamp frame ranges if (framenr < startframe) { BKE_ptcache_invalidate(cache); return; @@ -3687,6 +3682,22 @@ void sbObjectStep_admmpd( framenr = endframe; } + // BKE_ptcache_validate: + // sets flag that simulation is valid (|=) + // and sets simframe to framenr + // Calling BKE_ptcache_id_reset calls + // free_softbody_intern + + // Reset cache +// if (sb->admmpd && sb->admmpd->mesh_totverts != numVerts) +// { +// cache->flag |= PTCACHE_OUTDATED; +// BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); +// BKE_ptcache_validate(cache, 0); +// cache->last_exact = 0; +// cache->flag &= ~PTCACHE_REDO_NEEDED; +// } + // If it's the first frame we reset the cache and data if (framenr == startframe || sb->admmpd == NULL) { BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED); @@ -3710,8 +3721,17 @@ void sbObjectStep_admmpd( cache_result == PTCACHE_READ_INTERPOLATED || (!can_simulate && cache_result == PTCACHE_READ_OLD)) { + // Copies bodypoint vertices to ADMM internal verts admmpd_copy_from_bodypoint(sb->admmpd,sb->bpoint); + // Maps ADMM internal verts to surface verts admmpd_copy_to_bodypoint_and_object(sb->admmpd,NULL,vertexCos); + if(sb->local==0) + { + for (int i=0; i<me->totvert; ++i) + { + mul_m4_v3(ob->imat, vertexCos[i]); + } + } BKE_ptcache_validate(cache, framenr); if (cache_result == PTCACHE_READ_INTERPOLATED && @@ -3724,6 +3744,7 @@ void sbObjectStep_admmpd( } else if (cache_result == PTCACHE_READ_OLD) {} // pass else if (cache->flag & PTCACHE_BAKED) { + // if baked and nothing in cache, do nothing if (can_write_cache) { BKE_ptcache_invalidate(cache); @@ -3732,7 +3753,9 @@ void sbObjectStep_admmpd( } if (!can_simulate) + { return; + } } // end read from cache // if on second frame, write cache for first frame @@ -3744,8 +3767,13 @@ void sbObjectStep_admmpd( // Update ADMMPD interface variables from cache // and perform a solve. admmpd_copy_from_bodypoint(sb->admmpd,sb->bpoint); + admmpd_solve(sb->admmpd); admmpd_copy_to_bodypoint_and_object(sb->admmpd,sb->bpoint,vertexCos); + for (int i=0; i<me->totvert; ++i) + { // TODO move this to admmpd API + mul_m4_v3(ob->imat, vertexCos[i]); + } // Write cache BKE_ptcache_validate(cache, framenr); |