[Bf-blender-cvs] [30116a52749] master: Fix T65109: Object deleted when removed from the RigidBodyWorld collection.

Bastien Montagne noreply at git.blender.org
Thu Jun 13 18:02:53 CEST 2019


Commit: 30116a5274930ece7acaf8b4c6d5e389b32f8b69
Author: Bastien Montagne
Date:   Thu Jun 13 17:57:55 2019 +0200
Branches: master
https://developer.blender.org/rB30116a5274930ece7acaf8b4c6d5e389b32f8b69

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.

===================================================================

M	source/blender/blenkernel/intern/rigidbody.c

===================================================================

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);
   }



More information about the Bf-blender-cvs mailing list