Fix T60660: Texture paint undo removes image
authorCampbell Barton <ideasman42@gmail.com>
Thu, 31 Jan 2019 01:01:38 +0000 (12:01 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 31 Jan 2019 01:07:13 +0000 (12:07 +1100)
source/blender/editors/include/ED_util.h
source/blender/editors/sculpt_paint/paint_image_undo.c
source/blender/editors/undo/memfile_undo.c
source/blender/editors/util/ed_util.c

index 3903982..69699a0 100644 (file)
@@ -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);
index b049e61..25f5d91 100644 (file)
@@ -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)
index dc1870c..0180b3d 100644 (file)
@@ -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));
 }
 
index 1d56ef2..ad07f8c 100644 (file)
@@ -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"
 
 /* ********* 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);