diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-06-13 18:57:55 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-06-13 19:02:43 +0300 |
commit | 30116a5274930ece7acaf8b4c6d5e389b32f8b69 (patch) | |
tree | ba5ed3a7f413e847f076d525215da450854e4d1a /source/blender/blenkernel | |
parent | 245129e8e2a6fb24b7a3c6623eae9a6b2010c238 (diff) |
Fix T65109: Object deleted when removed from the RigidBodyWorld collection.
While user should never do that, it appears many end up using a 'view
layer' instancing collection as RBW collection, and even worse, have
objects in that unique collection.
Therefore, when removing RB simulation from an object, which among other
things has to remove it from the RBW collection, it would fully delete
the object from the blend file.
This fix merely checks the usercount of RB-removed object, and if it is
at 1 (which means object was in a single collection), it adds it to the
scene's master collection first.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/rigidbody.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index ad15214c3b8..d4d753eb685 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1326,6 +1326,15 @@ void BKE_rigidbody_remove_object(struct Main *bmain, Scene *scene, Object *ob) } FOREACH_COLLECTION_OBJECT_RECURSIVE_END; } + + /* Relying on usercount of the object should be OK, and it is much cheaper than looping in all + * collections to check whether the object is already in another one... */ + if (ID_REAL_USERS(&ob->id) == 1) { + /* Some users seems to find it funny to use a view-layer instancing collection + * as RBW collection... Despite this being a bad (ab)use of the system, avoid losing objects + * when we remove them from RB simulation. */ + BKE_collection_object_add(bmain, BKE_collection_master(scene), ob); + } BKE_collection_object_remove(bmain, rbw->group, ob, false); } |