[Bf-blender-cvs] [d6c0f3796a3] master: Fix T61049: Undo dynamic topology sculpt asserts

Campbell Barton noreply at git.blender.org
Thu Feb 7 04:25:42 CET 2019


Commit: d6c0f3796a3dd6d9fb6996e1e7d12633f982e560
Author: Campbell Barton
Date:   Thu Feb 7 13:22:31 2019 +1100
Branches: master
https://developer.blender.org/rBd6c0f3796a3dd6d9fb6996e1e7d12633f982e560

Fix T61049: Undo dynamic topology sculpt asserts

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

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

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

diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index d8a85c33e55..1b8e6da6ee3 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -48,6 +48,7 @@
 #include "BKE_key.h"
 #include "BKE_mesh.h"
 #include "BKE_mesh_runtime.h"
+#include "BKE_scene.h"
 #include "BKE_subsurf.h"
 #include "BKE_subdiv_ccg.h"
 #include "BKE_undo_system.h"
@@ -1098,11 +1099,35 @@ static void sculpt_undosys_step_decode_redo(struct bContext *C, SculptUndoStep *
 	}
 }
 
-static void sculpt_undosys_step_decode(struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p, int dir)
+static void sculpt_undosys_step_decode(struct bContext *C, struct Main *bmain, UndoStep *us_p, int dir)
 {
-	/* TODO(campbell): undo_system: use low-level API to set mode. */
-	ED_object_mode_set(C, OB_MODE_SCULPT);
-	BLI_assert(sculpt_undosys_poll(C));
+	/* Ensure sculpt mode. */
+	{
+		Scene *scene = CTX_data_scene(C);
+		ViewLayer *view_layer = CTX_data_view_layer(C);
+		/* Sculpt needs evaluated state. */
+		BKE_scene_view_layer_graph_evaluated_ensure(bmain, scene, view_layer);
+		Object *ob = OBACT(view_layer);
+		if (ob && (ob->type == OB_MESH)) {
+			Depsgraph *depsgraph = CTX_data_depsgraph(C);
+			if (ob->mode & OB_MODE_SCULPT) {
+				/* pass */
+			}
+			else {
+				ED_object_mode_generic_exit(bmain, depsgraph, scene, ob);
+				Mesh *me = ob->data;
+				/* Don't add sculpt topology undo steps when reading back undo state.
+				 * The undo steps must enter/exit for us. */
+				me->flag &= ~ME_SCULPT_DYNAMIC_TOPOLOGY;
+				ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, NULL);
+			}
+			BLI_assert(sculpt_undosys_poll(C));
+		}
+		else {
+			BLI_assert(0);
+			return;
+		}
+	}
 
 	SculptUndoStep *us = (SculptUndoStep *)us_p;
 	if (dir < 0) {



More information about the Bf-blender-cvs mailing list