[Bf-blender-cvs] [8c897906749] master: Fix T60660: Texture paint undo removes image

Campbell Barton noreply at git.blender.org
Thu Jan 31 02:04:31 CET 2019


Commit: 8c89790674901748cf04771dc2c5453815db1607
Author: Campbell Barton
Date:   Thu Jan 31 12:01:38 2019 +1100
Branches: master
https://developer.blender.org/rB8c89790674901748cf04771dc2c5453815db1607

Fix T60660: Texture paint undo removes image

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

M	source/blender/editors/include/ED_util.h
M	source/blender/editors/sculpt_paint/paint_image_undo.c
M	source/blender/editors/undo/memfile_undo.c
M	source/blender/editors/util/ed_util.c

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

diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h
index 390398262f9..69699a079a0 100644
--- a/source/blender/editors/include/ED_util.h
+++ b/source/blender/editors/include/ED_util.h
@@ -38,6 +38,7 @@ struct bContext;
 struct wmOperatorType;
 
 /* ed_util.c */
+void ED_editors_init_for_undo(struct Main *bmain);
 void ED_editors_init(struct bContext *C);
 void ED_editors_exit(struct Main *bmain, bool do_undo_system);
 bool ED_editors_flush_edits(struct Main *bmain, bool for_render);
diff --git a/source/blender/editors/sculpt_paint/paint_image_undo.c b/source/blender/editors/sculpt_paint/paint_image_undo.c
index b049e613b86..25f5d91a928 100644
--- a/source/blender/editors/sculpt_paint/paint_image_undo.c
+++ b/source/blender/editors/sculpt_paint/paint_image_undo.c
@@ -46,6 +46,7 @@
 
 #include "ED_paint.h"
 #include "ED_undo.h"
+#include "ED_util.h"
 
 #include "GPU_draw.h"
 
@@ -466,13 +467,16 @@ static bool image_undosys_step_encode(struct bContext *UNUSED(C), struct Main *U
 	return true;
 }
 
-static void image_undosys_step_decode(struct bContext *UNUSED(C), struct Main *UNUSED(bmain), UndoStep *us_p, int UNUSED(dir))
+static void image_undosys_step_decode(struct bContext *UNUSED(C), struct Main *bmain, UndoStep *us_p, int UNUSED(dir))
 {
 	ImageUndoStep *us = (ImageUndoStep *)us_p;
 #if 0
 	paint_undosys_step_decode_restore_ids(us);
 #endif
 	image_undo_restore_list(&us->tiles, us->id_map);
+
+	/* Refresh texture slots. */
+	ED_editors_init_for_undo(bmain);
 }
 
 static void image_undosys_step_free(UndoStep *us_p)
diff --git a/source/blender/editors/undo/memfile_undo.c b/source/blender/editors/undo/memfile_undo.c
index dc1870c2d19..0180b3dde81 100644
--- a/source/blender/editors/undo/memfile_undo.c
+++ b/source/blender/editors/undo/memfile_undo.c
@@ -93,6 +93,10 @@ static void memfile_undosys_step_decode(struct bContext *C, struct Main *bmain,
 	MemFileUndoStep *us = (MemFileUndoStep *)us_p;
 	BKE_memfile_undo_decode(us->data, C);
 
+	/* bmain has been freed. */
+	bmain = CTX_data_main(C);
+	ED_editors_init_for_undo(bmain);
+
 	WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, CTX_data_scene(C));
 }
 
diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c
index 1d56ef24403..ad07f8c6a8f 100644
--- a/source/blender/editors/util/ed_util.c
+++ b/source/blender/editors/util/ed_util.c
@@ -59,6 +59,7 @@
 #include "BKE_screen.h"
 #include "BKE_undo_system.h"
 #include "BKE_workspace.h"
+#include "BKE_material.h"
 
 #include "ED_armature.h"
 #include "ED_buttons.h"
@@ -85,6 +86,24 @@
 
 /* ********* general editor util funcs, not BKE stuff please! ********* */
 
+void ED_editors_init_for_undo(Main *bmain)
+{
+	wmWindowManager *wm = bmain->wm.first;
+	for (wmWindow *win = wm->windows.first; win; win = win->next) {
+		ViewLayer *view_layer = WM_window_get_active_view_layer(win);
+		Base *base = BASACT(view_layer);
+		if (base != NULL) {
+			Object *ob = base->object;
+			if (ob->mode & OB_MODE_TEXTURE_PAINT) {
+				Scene *scene = WM_window_get_active_scene(win);
+
+				BKE_texpaint_slots_refresh_object(scene, ob);
+				BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
+			}
+		}
+	}
+}
+
 void ED_editors_init(bContext *C)
 {
 	struct Depsgraph *depsgraph = CTX_data_depsgraph(C);



More information about the Bf-blender-cvs mailing list