[Bf-blender-cvs] [2ce94cc24b2] blender2.8: Fix crash opening files saved in sculpt/vertex paint modes

Sergey Sharybin noreply at git.blender.org
Tue May 1 10:24:41 CEST 2018


Commit: 2ce94cc24b2ce5fdb89ae5d503aaabe22687e285
Author: Sergey Sharybin
Date:   Tue May 1 10:14:20 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB2ce94cc24b2ce5fdb89ae5d503aaabe22687e285

Fix crash opening files saved in sculpt/vertex paint modes

Skip access to any evaluated data when operator is run on file load,
we don't have depsgraph evaluated yet. In this case we skip part of
sculpt session initialization, since it will be done during depsgraph
evaluation which happens after DEG_on_visible_update().

We can not skip sculpt session initialization since during normal
operation we want all the data to be initialized on mode change,
and not on initial brush stroke.

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

M	source/blender/blenkernel/BKE_context.h
M	source/blender/blenkernel/intern/context.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index e50c33e258c..12525fe9a50 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -322,6 +322,11 @@ int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list);
 
 struct Depsgraph *CTX_data_depsgraph(const bContext *C);
 
+/* Will Return NULL if depsgraph is not allocated yet.
+ * Only used by handful of operators which are run on file load.
+ */
+struct Depsgraph *CTX_data_depsgraph_on_load(const bContext *C);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 72832e9f897..f420fd974cd 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -1244,3 +1244,10 @@ Depsgraph *CTX_data_depsgraph(const bContext *C)
 	ViewLayer *view_layer = CTX_data_view_layer(C);
 	return BKE_scene_get_depsgraph(scene, view_layer, true);
 }
+
+Depsgraph *CTX_data_depsgraph_on_load(const bContext *C)
+{
+	Scene *scene = CTX_data_scene(C);
+	ViewLayer *view_layer = CTX_data_view_layer(C);
+	return BKE_scene_get_depsgraph(scene, view_layer, false);
+}
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 4681f54e26f..4056a15fe47 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -865,6 +865,15 @@ void BKE_sculpt_update_mesh_elements(
         Depsgraph *depsgraph, Scene *scene, Sculpt *sd, Object *ob,
         bool need_pmap, bool need_mask)
 {
+	if (depsgraph == NULL) {
+		/* Happens on file load.
+		 *
+		 * We do nothing in this case, it will be taken care about on depsgraph
+		 * evaluation.
+		 */
+		return;
+	}
+
 	DerivedMesh *dm;
 	SculptSession *ss = ob->sculpt;
 	Mesh *me = ob->data;
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 1775d4b9c8b..7e9c98d3822 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -2342,7 +2342,7 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op)
 		ED_object_vpaintmode_exit_ex(ob);
 	}
 	else {
-		Depsgraph *depsgraph = CTX_data_depsgraph(C);
+		Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C);
 		wmWindowManager *wm = CTX_wm_manager(C);
 		ED_object_vpaintmode_enter_ex(depsgraph, wm, scene, ob);
 	}
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 1d1c8460cfd..9817ca41832 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -5793,7 +5793,7 @@ void ED_object_sculptmode_exit(bContext *C)
 
 static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
 {
-	Depsgraph *depsgraph = CTX_data_depsgraph(C);
+	Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C);
 	Scene *scene = CTX_data_scene(C);
 	Object *ob = CTX_data_active_object(C);
 	const int mode_flag = OB_MODE_SCULPT;



More information about the Bf-blender-cvs mailing list