[Bf-blender-cvs] [ad5f1d02318] master: Fix T71605: Crash toggling dynamic topology in background mode

Campbell Barton noreply at git.blender.org
Sat Sep 12 05:42:56 CEST 2020


Commit: ad5f1d02318a30c545196f124e30504615294416
Author: Campbell Barton
Date:   Sat Sep 12 13:38:12 2020 +1000
Branches: master
https://developer.blender.org/rBad5f1d02318a30c545196f124e30504615294416

Fix T71605: Crash toggling dynamic topology in background mode

Support toggling without an undo stack in background mode.

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

M	source/blender/editors/sculpt_paint/sculpt_dyntopo.c

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

diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
index f07d22ed639..9b4b5b8d1e2 100644
--- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
@@ -36,6 +36,7 @@
 
 #include "BKE_brush.h"
 #include "BKE_context.h"
+#include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_mapping.h"
@@ -58,6 +59,7 @@
 #include "ED_object.h"
 #include "ED_screen.h"
 #include "ED_sculpt.h"
+#include "ED_undo.h"
 #include "ED_view3d.h"
 #include "paint_intern.h"
 #include "sculpt_intern.h"
@@ -285,11 +287,17 @@ void sculpt_dynamic_topology_disable_with_undo(Main *bmain,
                                                Object *ob)
 {
   SculptSession *ss = ob->sculpt;
-  if (ss->bm) {
-    SCULPT_undo_push_begin("Dynamic topology disable");
-    SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_END);
+  if (ss->bm != NULL) {
+    /* May be false in background mode. */
+    const bool use_undo = G.background ? (ED_undo_stack_get() != NULL) : true;
+    if (use_undo) {
+      SCULPT_undo_push_begin("Dynamic topology disable");
+      SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_END);
+    }
     SCULPT_dynamic_topology_disable_ex(bmain, depsgraph, scene, ob, NULL);
-    SCULPT_undo_push_end();
+    if (use_undo) {
+      SCULPT_undo_push_end();
+    }
   }
 }
 
@@ -300,10 +308,16 @@ static void sculpt_dynamic_topology_enable_with_undo(Main *bmain,
 {
   SculptSession *ss = ob->sculpt;
   if (ss->bm == NULL) {
-    SCULPT_undo_push_begin("Dynamic topology enable");
+    /* May be false in background mode. */
+    const bool use_undo = G.background ? (ED_undo_stack_get() != NULL) : true;
+    if (use_undo) {
+      SCULPT_undo_push_begin("Dynamic topology enable");
+    }
     SCULPT_dynamic_topology_enable_ex(bmain, depsgraph, scene, ob);
-    SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN);
-    SCULPT_undo_push_end();
+    if (use_undo) {
+      SCULPT_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN);
+      SCULPT_undo_push_end();
+    }
   }
 }



More information about the Bf-blender-cvs mailing list