diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-03-11 12:07:36 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-03-11 16:34:13 +0300 |
commit | 57777b95428cef886bd3b2317b7728fa066acee1 (patch) | |
tree | e7555b4ccba56fc33c1a09155c4f25bbcb0d8c1f /source/blender/blenkernel | |
parent | 2cb181d478c3f54adf91188beca0b3fd3e28bcaf (diff) |
Fix T61906: crash rendering softbody with Cycles and timeline visible.
Make sure we don't reallocate arrays in the pointcache when not needed, the
size of a memory allocation can be slightly bigger than the requested size.
Also, use consistent check for shared cached in copy and free functions.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/pointcache.c | 15 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/softbody.c | 2 |
2 files changed, 11 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index ed949e68f13..3371c3dbe48 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -3202,7 +3202,7 @@ int BKE_ptcache_id_exist(PTCacheID *pid, int cfra) if (cfra<pid->cache->startframe || cfra > pid->cache->endframe) return 0; - if (pid->cache->cached_frames && pid->cache->cached_frames[cfra-pid->cache->startframe]==0) + if (pid->cache->cached_frames && pid->cache->cached_frames[cfra-pid->cache->startframe]==0) return 0; if (pid->cache->flag & PTCACHE_DISK_CACHE) { @@ -3258,9 +3258,10 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra /* verify cached_frames array is up to date */ if (cache->cached_frames) { - if (MEM_allocN_len(cache->cached_frames) != sizeof(char) * (cache->endframe-cache->startframe+1)) { + if (cache->cached_frames_len != (cache->endframe - cache->startframe + 1)) { MEM_freeN(cache->cached_frames); cache->cached_frames = NULL; + cache->cached_frames_len = 0; } } @@ -3268,7 +3269,8 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra unsigned int sta=cache->startframe; unsigned int end=cache->endframe; - cache->cached_frames = MEM_callocN(sizeof(char) * (cache->endframe-cache->startframe+1), "cached frames array"); + cache->cached_frames_len = cache->endframe - cache->startframe + 1; + cache->cached_frames = MEM_callocN(sizeof(char) * cache->cached_frames_len, "cached frames array"); if (pid->cache->flag & PTCACHE_DISK_CACHE) { /* mode is same as fopen's modes */ @@ -3544,6 +3546,7 @@ static PointCache *ptcache_copy(PointCache *cache, const bool copy_data) if (copy_data == false) { ncache->cached_frames = NULL; + ncache->cached_frames_len = 0; /* flag is a mix of user settings and simulator/baking state */ ncache->flag= ncache->flag & (PTCACHE_DISK_CACHE|PTCACHE_EXTERNAL|PTCACHE_IGNORE_LIBPATH); @@ -3902,7 +3905,8 @@ void BKE_ptcache_toggle_disk_cache(PTCacheID *pid) if (cache->cached_frames) { MEM_freeN(cache->cached_frames); - cache->cached_frames=NULL; + cache->cached_frames = NULL; + cache->cached_frames_len = 0; } if (cache->flag & PTCACHE_DISK_CACHE) @@ -4082,7 +4086,8 @@ void BKE_ptcache_load_external(PTCacheID *pid) /* make sure all new frames are loaded */ if (cache->cached_frames) { MEM_freeN(cache->cached_frames); - cache->cached_frames=NULL; + cache->cached_frames = NULL; + cache->cached_frames_len = 0; } BKE_ptcache_update_info(pid); } diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index a1e2e0971d1..481eb617cc0 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -3037,7 +3037,7 @@ void sbFree(Object *ob) free_softbody_intern(sb); - if ((ob->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0) { + if ((ob->id.tag & LIB_TAG_NO_MAIN) == 0) { /* Only free shared data on non-CoW copies */ BKE_ptcache_free_list(&sb->shared->ptcaches); sb->shared->pointcache = NULL; |