From 39439a3afe18bb614e7ada1f61682b602a6c0549 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 26 Aug 2019 16:01:16 +0200 Subject: 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... --- source/blender/blenkernel/intern/pointcache.c | 56 +++++++++++++++------------ 1 file changed, 31 insertions(+), 25 deletions(-) (limited to 'source/blender/blenkernel/intern/pointcache.c') 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; } -- cgit v1.2.3