[Bf-blender-cvs] [a5b6d6de0a2] blender-v2.90-release: Fix T80885: Texture paint camera project crashes after undo/redo

Campbell Barton noreply at git.blender.org
Mon Sep 21 09:50:37 CEST 2020


Commit: a5b6d6de0a2b3cec82cd914d58d0c435dace55b0
Author: Campbell Barton
Date:   Fri Sep 18 14:17:17 2020 +1000
Branches: blender-v2.90-release
https://developer.blender.org/rBa5b6d6de0a2b3cec82cd914d58d0c435dace55b0

Fix T80885: Texture paint camera project crashes after undo/redo

Unmatched ED_image_undo_push_{begin/end},
add doc-strings noting why this is needed.

Thanks to @Baardaap for the initial fix.

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

M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/space_image/image_undo.c

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

diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 5af3a3f4241..cc60d73eef0 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -6114,8 +6114,6 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
 
   scene->toolsettings->imapaint.flag |= IMAGEPAINT_DRAWING;
 
-  ED_image_undo_push_begin(op->type->name, PAINT_MODE_TEXTURE_3D);
-
   /* allocate and initialize spatial data structures */
   project_paint_begin(C, &ps, false, 0);
 
@@ -6125,8 +6123,10 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
 
-  float pos[2] = {0.0, 0.0};
-  float lastpos[2] = {0.0, 0.0};
+  ED_image_undo_push_begin(op->type->name, PAINT_MODE_TEXTURE_3D);
+
+  const float pos[2] = {0.0, 0.0};
+  const float lastpos[2] = {0.0, 0.0};
   int a;
 
   project_paint_op(&ps, lastpos, pos);
@@ -6140,6 +6140,8 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
 
   project_paint_end(&ps);
 
+  ED_image_undo_push_end();
+
   scene->toolsettings->imapaint.flag &= ~IMAGEPAINT_DRAWING;
   BKE_brush_size_set(scene, ps.brush, orig_brush_size);
 
diff --git a/source/blender/editors/space_image/image_undo.c b/source/blender/editors/space_image/image_undo.c
index e0c44c3a0ba..ce4e9195723 100644
--- a/source/blender/editors/space_image/image_undo.c
+++ b/source/blender/editors/space_image/image_undo.c
@@ -1005,6 +1005,14 @@ void ED_image_undosys_type(UndoType *ut)
 
 /* -------------------------------------------------------------------- */
 /** \name Utilities
+ *
+ * \note image undo exposes #ED_image_undo_push_begin, #ED_image_undo_push_end
+ * which must be called by the operator directly.
+ *
+ * Unlike most other undo stacks this is needed:
+ * - So we can always access the state before the image was painted onto,
+ *   which is needed if previous undo states aren't image-type.
+ * - So operators can access the pixel-data before the stroke was applied, at run-time.
  * \{ */
 
 ListBase *ED_image_paint_tile_list_get(void)
@@ -1042,6 +1050,10 @@ static ImageUndoStep *image_undo_push_begin(const char *name, int paint_mode)
   return us;
 }
 
+/**
+ * The caller is responsible for running #ED_image_undo_push_end,
+ * failure to do so causes an invalid state for the undo system.
+ */
 void ED_image_undo_push_begin(const char *name, int paint_mode)
 {
   image_undo_push_begin(name, paint_mode);



More information about the Bf-blender-cvs mailing list