Commit: 1342d1879e121b1cf4118a232139d906a7da1ee6
Author: Bastien Montagne
Date:   Thu Aug 8 17:16:54 2019 +0200
Branches: master
https://developer.blender.org/rB1342d1879e121b1cf4118a232139d906a7da1ee6

Fix T52551: undo causes crash after enabling a new rigid body when scene uses a 
referenced rigid body world.

Poll functions were not correct here, we cannot make objects part of
rigidbody sim if the RB collection is a linked one...

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

M       source/blender/editors/physics/rigidbody_constraint.c
M       source/blender/editors/physics/rigidbody_object.c
M       source/blender/editors/screen/screen_ops.c

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

diff --git a/source/blender/editors/physics/rigidbody_constraint.c 
b/source/blender/editors/physics/rigidbody_constraint.c
index 2c454448b9b..a1d76174cc8 100644
--- a/source/blender/editors/physics/rigidbody_constraint.c
+++ b/source/blender/editors/physics/rigidbody_constraint.c
@@ -46,6 +46,7 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "ED_object.h"
 #include "ED_physics.h"
 #include "ED_screen.h"
 
@@ -56,12 +57,37 @@
 
 static bool ED_operator_rigidbody_con_active_poll(bContext *C)
 {
+  Scene *scene = CTX_data_scene(C);
+  if (scene == NULL || ID_IS_LINKED(&scene->id) ||
+      (scene->rigidbody_world != NULL && scene->rigidbody_world->constraints 
!= NULL &&
+       ID_IS_LINKED(&scene->rigidbody_world->constraints->id))) {
+    return false;
+  }
+
   if (ED_operator_object_active_editable(C)) {
-    Object *ob = CTX_data_active_object(C);
+    Object *ob = ED_object_active_context(C);
     return (ob && ob->rigidbody_constraint);
   }
   else {
-    return 0;
+    return false;
+  }
+}
+
+static bool ED_operator_rigidbody_con_add_poll(bContext *C)
+{
+  Scene *scene = CTX_data_scene(C);
+  if (scene == NULL || ID_IS_LINKED(&scene->id) ||
+      (scene->rigidbody_world != NULL && scene->rigidbody_world->constraints 
!= NULL &&
+       ID_IS_LINKED(&scene->rigidbody_world->constraints->id))) {
+    return false;
+  }
+
+  if (ED_operator_object_active_editable(C)) {
+    Object *ob = ED_object_active_context(C);
+    return (ob && ob->type == OB_MESH);
+  }
+  else {
+    return false;
   }
 }
 
@@ -152,7 +178,7 @@ void RIGIDBODY_OT_constraint_add(wmOperatorType *ot)
 
   /* callbacks */
   ot->exec = rigidbody_con_add_exec;
-  ot->poll = ED_operator_object_active_editable;
+  ot->poll = ED_operator_rigidbody_con_add_poll;
 
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
diff --git a/source/blender/editors/physics/rigidbody_object.c 
b/source/blender/editors/physics/rigidbody_object.c
index 70142b790c0..bc8a1799fa0 100644
--- a/source/blender/editors/physics/rigidbody_object.c
+++ b/source/blender/editors/physics/rigidbody_object.c
@@ -62,6 +62,13 @@
 
 static bool ED_operator_rigidbody_active_poll(bContext *C)
 {
+  Scene *scene = CTX_data_scene(C);
+  if (scene == NULL || ID_IS_LINKED(&scene->id) ||
+      (scene->rigidbody_world != NULL && scene->rigidbody_world->group != NULL 
&&
+       ID_IS_LINKED(&scene->rigidbody_world->group->id))) {
+    return false;
+  }
+
   if (ED_operator_object_active_editable(C)) {
     Object *ob = ED_object_active_context(C);
     return (ob && ob->rigidbody_object);
@@ -73,12 +80,19 @@ static bool ED_operator_rigidbody_active_poll(bContext *C)
 
 static bool ED_operator_rigidbody_add_poll(bContext *C)
 {
+  Scene *scene = CTX_data_scene(C);
+  if (scene == NULL || ID_IS_LINKED(&scene->id) ||
+      (scene->rigidbody_world != NULL && scene->rigidbody_world->group != NULL 
&&
+       ID_IS_LINKED(&scene->rigidbody_world->group->id))) {
+    return false;
+  }
+
   if (ED_operator_object_active_editable(C)) {
     Object *ob = ED_object_active_context(C);
     return (ob && ob->type == OB_MESH);
   }
   else {
-    return 0;
+    return false;
   }
 }
 
@@ -286,7 +300,7 @@ void RIGIDBODY_OT_objects_remove(wmOperatorType *ot)
 
   /* callbacks */
   ot->exec = rigidbody_objects_remove_exec;
-  ot->poll = ED_operator_scene_editable;
+  ot->poll = ED_operator_rigidbody_active_poll;
 
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -341,7 +355,7 @@ void RIGIDBODY_OT_shape_change(wmOperatorType *ot)
   /* callbacks */
   ot->invoke = WM_menu_invoke;
   ot->exec = rigidbody_objects_shape_change_exec;
-  ot->poll = ED_operator_scene_editable;
+  ot->poll = ED_operator_rigidbody_active_poll;
 
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -534,7 +548,7 @@ void RIGIDBODY_OT_mass_calculate(wmOperatorType *ot)
   /* callbacks */
   ot->invoke = WM_menu_invoke;  // XXX
   ot->exec = rigidbody_objects_calc_mass_exec;
-  ot->poll = ED_operator_scene_editable;
+  ot->poll = ED_operator_rigidbody_active_poll;
 
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
diff --git a/source/blender/editors/screen/screen_ops.c 
b/source/blender/editors/screen/screen_ops.c
index eccd85ab276..4fb5e0c1af3 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -186,9 +186,9 @@ bool ED_operator_scene_editable(bContext *C)
 {
   Scene *scene = CTX_data_scene(C);
   if (scene && !ID_IS_LINKED(scene)) {
-    return 1;
+    return true;
   }
-  return 0;
+  return false;
 }
 
 bool ED_operator_objectmode(bContext *C)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to