Fix T57653: Fix T58075: Crash when switching between Edit and Sculpt/Paint modes.
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 29 Nov 2018 09:31:56 +0000 (10:31 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 29 Nov 2018 09:42:56 +0000 (10:42 +0100)
Sculpt (and paint) modes rely on valid evaluated data at their initialization.

Added code to ensure that in `ED_object_mode_toggle()`, when relevant
toggle operator requires it (looks like sculpt/paint should be the only
ones affected, although particle edit may be too...).

source/blender/editors/object/object_modes.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/sculpt.c

index ee075a94d296b95872b6e07dd8578ee50184633b..10c7fcfeba1cfbe4c0f90de80e77bbd329111542 100644 (file)
 #include "BLI_utildefines.h"
 
 #include "BKE_context.h"
+#include "BKE_layer.h"
 #include "BKE_object.h"
 #include "BKE_paint.h"
 #include "BKE_report.h"
-#include "BKE_layer.h"
+#include "BKE_scene.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -161,7 +162,16 @@ void ED_object_mode_toggle(bContext *C, eObjectMode mode)
                const char *opstring = object_mode_op_string(mode);
 
                if (opstring) {
-                       WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
+                       wmOperatorType *ot = WM_operatortype_find(opstring, false);
+                       if (ot->flag & OPTYPE_USE_EVAL_DATA) {
+                               /* We need to force refresh of depsgraph after undo step,
+                                * redoing the operator *may* rely on some valid evaluated data. */
+                               struct Main *bmain = CTX_data_main(C);
+                               Scene *scene = CTX_data_scene(C);
+                               ViewLayer *view_layer = CTX_data_view_layer(C);
+                               BKE_scene_view_layer_graph_evaluated_ensure(bmain, scene, view_layer);
+                       }
+                       WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_REGION_WIN, NULL);
                }
        }
 }
index a604bd5feb6b40e52c25ec247166a39c66a14c65..9d078d4fea2b9ebe069422e701ebac2fe74d7be2 100644 (file)
@@ -1320,7 +1320,7 @@ void PAINT_OT_weight_paint_toggle(wmOperatorType *ot)
        ot->poll = paint_poll_test;
 
        /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
 }
 
 /* ************ weight paint operator ********** */
@@ -2450,7 +2450,7 @@ void PAINT_OT_vertex_paint_toggle(wmOperatorType *ot)
        ot->poll = paint_poll_test;
 
        /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
 }
 
 
index a497d555296d13bf53557a2fefb6ff9e51b7915e..ef4f9a9c7bf1266ebcde2cf335a846562f842a3d 100644 (file)
@@ -5859,7 +5859,7 @@ static void SCULPT_OT_sculptmode_toggle(wmOperatorType *ot)
        ot->exec = sculpt_mode_toggle_exec;
        ot->poll = ED_operator_object_active_editable_mesh;
 
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
 }
 
 static bool sculpt_and_constant_or_manual_detail_poll(bContext *C)