diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-08-26 17:01:16 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-08-26 17:03:58 +0300 |
commit | 39439a3afe18bb614e7ada1f61682b602a6c0549 (patch) | |
tree | e0dc188ccd4008236594b6dbf6c03b1a17eb02b9 /source/blender/blenkernel/intern/pointcache.c | |
parent | 51d9f56f874d2aeea0dc8bc256eb9e12d1726187 (diff) |
Fix T69156: Blender crash when baking rigid body world.
Issue was exposed by recent own rB03bf84db86b commit, but was actually
present in RNA API for PointCaches since (probably) ages: whole accessor
code here was assuming that owner ID was an Object, when it is actually
a scene for RigidBody simulations...
Had also to make `BKE_ptcache_id_find()` and friends a bit more
flexible, now they also accept a NULL object pointer parameter...
Diffstat (limited to 'source/blender/blenkernel/intern/pointcache.c')
-rw-r--r-- | source/blender/blenkernel/intern/pointcache.c | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 13d0f1adb84..5f073120383 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1831,6 +1831,7 @@ void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, Object *ob, RigidBodyWorld *r pid->file_type = PTCACHE_FILE_PTCACHE; } +/** Both \param ob and \param scene may be NULL. */ PTCacheID BKE_ptcache_id_find(Object *ob, Scene *scene, PointCache *cache) { PTCacheID result = {0}; @@ -1934,40 +1935,45 @@ static bool foreach_object_ptcache( Scene *scene, Object *object, int duplis, ForeachPtcacheCb callback, void *callback_user_data) { PTCacheID pid; - /* Soft body. */ - if (object->soft != NULL) { - BKE_ptcache_id_from_softbody(&pid, object, object->soft); - if (!callback(&pid, callback_user_data)) { + + if (object != NULL) { + /* Soft body. */ + if (object->soft != NULL) { + BKE_ptcache_id_from_softbody(&pid, object, object->soft); + if (!callback(&pid, callback_user_data)) { + return false; + } + } + /* Particle systems. */ + if (!foreach_object_particle_ptcache(object, callback, callback_user_data)) { return false; } + /* Modifiers. */ + if (!foreach_object_modifier_ptcache(object, callback, callback_user_data)) { + return false; + } + /* Consider all object in dupli groups to be part of the same object, + * for baking with linking dupligroups. Once we have better overrides + * this can be revisited so users select the local objects directly. */ + if (scene != NULL && (duplis-- > 0) && (object->instance_collection != NULL)) { + FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (object->instance_collection, current_object) { + if (current_object == object) { + continue; + } + foreach_object_ptcache(scene, current_object, duplis, callback, callback_user_data); + } + FOREACH_COLLECTION_OBJECT_RECURSIVE_END; + } } - /* Particle systems. */ - if (!foreach_object_particle_ptcache(object, callback, callback_user_data)) { - return false; - } - /* Modifiers. */ - if (!foreach_object_modifier_ptcache(object, callback, callback_user_data)) { - return false; - } + /* Rigid body. */ - if (scene != NULL && object->rigidbody_object != NULL && scene->rigidbody_world != NULL) { + if (scene != NULL && (object == NULL || object->rigidbody_object != NULL) && + scene->rigidbody_world != NULL) { BKE_ptcache_id_from_rigidbody(&pid, object, scene->rigidbody_world); if (!callback(&pid, callback_user_data)) { return false; } } - /* Consider all object in dupli groups to be part of the same object, - * for baking with linking dupligroups. Once we have better overrides - * this can be revisited so users select the local objects directly. */ - if (scene != NULL && (duplis-- > 0) && (object->instance_collection != NULL)) { - FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (object->instance_collection, current_object) { - if (current_object == object) { - continue; - } - foreach_object_ptcache(scene, current_object, duplis, callback, callback_user_data); - } - FOREACH_COLLECTION_OBJECT_RECURSIVE_END; - } return true; } |