[Bf-blender-cvs] [bc3e38ca3a4] master: Cleanup/refactor: UndoType: Clarify `use_context` variable.

Bastien Montagne noreply at git.blender.org
Wed Jan 6 12:28:11 CET 2021


Commit: bc3e38ca3a4228b7191e9fec39288c9f37ec53b1
Author: Bastien Montagne
Date:   Wed Jan 6 12:25:35 2021 +0100
Branches: master
https://developer.blender.org/rBbc3e38ca3a4228b7191e9fec39288c9f37ec53b1

Cleanup/refactor: UndoType: Clarify `use_context` variable.

Rename it to mark it is only for `encode` callbacks, fix `encode`
callback of text undo to early fail in case it gets a NULL context, add
an assert to `BKE_undosys_step_push_with_type` that context is not NULL
when undotype requires a valid one.

Note that in practice this should not change anything, currently it
seems that we always get a valid context in
`BKE_undosys_step_push_with_type`?

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

M	source/blender/blenkernel/BKE_undo_system.h
M	source/blender/blenkernel/intern/undo_system.c
M	source/blender/editors/armature/editarmature_undo.c
M	source/blender/editors/curve/editcurve_undo.c
M	source/blender/editors/curve/editfont_undo.c
M	source/blender/editors/lattice/editlattice_undo.c
M	source/blender/editors/mesh/editmesh_undo.c
M	source/blender/editors/metaball/editmball_undo.c
M	source/blender/editors/physics/particle_edit_undo.c
M	source/blender/editors/sculpt_paint/paint_curve_undo.c
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/editors/space_image/image_undo.c
M	source/blender/editors/space_text/text_undo.c
M	source/blender/editors/undo/memfile_undo.c

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

diff --git a/source/blender/blenkernel/BKE_undo_system.h b/source/blender/blenkernel/BKE_undo_system.h
index fff6c73fafa..9af4c07a4dc 100644
--- a/source/blender/blenkernel/BKE_undo_system.h
+++ b/source/blender/blenkernel/BKE_undo_system.h
@@ -140,7 +140,11 @@ typedef struct UndoType {
                               UndoTypeForEachIDRefFn foreach_ID_ref_fn,
                               void *user_data);
 
-  bool use_context;
+  /**
+   * This undo type `encode` callback needs a valid context, it will fail otherwise.
+   * \note Callback is still supposed to properly deal with a NULL context pointer.
+   */
+  bool use_context_for_encode;
 
   /**
    * The size of the undo struct 'inherited' from #UndoStep for that specific type. Used for
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index 078c93532d9..0713a2d6729 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -501,6 +501,8 @@ UndoPushReturn BKE_undosys_step_push_with_type(UndoStack *ustack,
                                                const char *name,
                                                const UndoType *ut)
 {
+  BLI_assert(ut->use_context_for_encode == false || C != NULL);
+
   UNDO_NESTED_ASSERT(false);
   undosys_stack_validate(ustack, false);
   bool is_not_empty = ustack->step_active != NULL;
diff --git a/source/blender/editors/armature/editarmature_undo.c b/source/blender/editors/armature/editarmature_undo.c
index 7c11c5e537e..d6b80909247 100644
--- a/source/blender/editors/armature/editarmature_undo.c
+++ b/source/blender/editors/armature/editarmature_undo.c
@@ -249,7 +249,7 @@ void ED_armature_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = armature_undosys_foreach_ID_ref;
 
-  ut->use_context = true;
+  ut->use_context_for_encode = true;
 
   ut->step_size = sizeof(ArmatureUndoStep);
 }
diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c
index 1fd1e217649..3fd3a348426 100644
--- a/source/blender/editors/curve/editcurve_undo.c
+++ b/source/blender/editors/curve/editcurve_undo.c
@@ -309,7 +309,7 @@ void ED_curve_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = curve_undosys_foreach_ID_ref;
 
-  ut->use_context = true;
+  ut->use_context_for_encode = true;
 
   ut->step_size = sizeof(CurveUndoStep);
 }
diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c
index 61c05f62af7..895db2b4ad1 100644
--- a/source/blender/editors/curve/editfont_undo.c
+++ b/source/blender/editors/curve/editfont_undo.c
@@ -398,7 +398,7 @@ void ED_font_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = font_undosys_foreach_ID_ref;
 
-  ut->use_context = true;
+  ut->use_context_for_encode = true;
 
   ut->step_size = sizeof(FontUndoStep);
 }
diff --git a/source/blender/editors/lattice/editlattice_undo.c b/source/blender/editors/lattice/editlattice_undo.c
index cfc9d162c37..393b9858e1d 100644
--- a/source/blender/editors/lattice/editlattice_undo.c
+++ b/source/blender/editors/lattice/editlattice_undo.c
@@ -283,7 +283,7 @@ void ED_lattice_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = lattice_undosys_foreach_ID_ref;
 
-  ut->use_context = true;
+  ut->use_context_for_encode = true;
 
   ut->step_size = sizeof(LatticeUndoStep);
 }
diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c
index cff5414da75..38ff58fb965 100644
--- a/source/blender/editors/mesh/editmesh_undo.c
+++ b/source/blender/editors/mesh/editmesh_undo.c
@@ -819,7 +819,7 @@ void ED_mesh_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = mesh_undosys_foreach_ID_ref;
 
-  ut->use_context = true;
+  ut->use_context_for_encode = true;
 
   ut->step_size = sizeof(MeshUndoStep);
 }
diff --git a/source/blender/editors/metaball/editmball_undo.c b/source/blender/editors/metaball/editmball_undo.c
index b4030ad269b..64443270c96 100644
--- a/source/blender/editors/metaball/editmball_undo.c
+++ b/source/blender/editors/metaball/editmball_undo.c
@@ -258,7 +258,7 @@ void ED_mball_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = mball_undosys_foreach_ID_ref;
 
-  ut->use_context = true;
+  ut->use_context_for_encode = true;
 
   ut->step_size = sizeof(MBallUndoStep);
 }
diff --git a/source/blender/editors/physics/particle_edit_undo.c b/source/blender/editors/physics/particle_edit_undo.c
index 7523571733e..5dbbf90639d 100644
--- a/source/blender/editors/physics/particle_edit_undo.c
+++ b/source/blender/editors/physics/particle_edit_undo.c
@@ -299,7 +299,7 @@ void ED_particle_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = particle_undosys_foreach_ID_ref;
 
-  ut->use_context = true;
+  ut->use_context_for_encode = true;
 
   ut->step_size = sizeof(ParticleUndoStep);
 }
diff --git a/source/blender/editors/sculpt_paint/paint_curve_undo.c b/source/blender/editors/sculpt_paint/paint_curve_undo.c
index 7ce7e73cbf2..82ed4917004 100644
--- a/source/blender/editors/sculpt_paint/paint_curve_undo.c
+++ b/source/blender/editors/sculpt_paint/paint_curve_undo.c
@@ -156,7 +156,7 @@ void ED_paintcurve_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = paintcurve_undosys_foreach_ID_ref;
 
-  ut->use_context = false;
+  ut->use_context_for_encode = false;
 
   ut->step_size = sizeof(PaintCurveUndoStep);
 }
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 5bbe18935cc..11a279b5a5a 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -1576,7 +1576,7 @@ void ED_sculpt_undosys_type(UndoType *ut)
   ut->step_decode = sculpt_undosys_step_decode;
   ut->step_free = sculpt_undosys_step_free;
 
-  ut->use_context = true;
+  ut->use_context_for_encode = true;
 
   ut->step_size = sizeof(SculptUndoStep);
 }
diff --git a/source/blender/editors/space_image/image_undo.c b/source/blender/editors/space_image/image_undo.c
index 7b1329793dc..2c8b0f2e0cf 100644
--- a/source/blender/editors/space_image/image_undo.c
+++ b/source/blender/editors/space_image/image_undo.c
@@ -995,7 +995,7 @@ void ED_image_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = image_undosys_foreach_ID_ref;
 
-  ut->use_context = true;
+  ut->use_context_for_encode = true;
 
   ut->step_size = sizeof(ImageUndoStep);
 }
diff --git a/source/blender/editors/space_text/text_undo.c b/source/blender/editors/space_text/text_undo.c
index 4126f36e44a..c6bcbc06b2f 100644
--- a/source/blender/editors/space_text/text_undo.c
+++ b/source/blender/editors/space_text/text_undo.c
@@ -183,11 +183,14 @@ static bool text_undosys_step_encode(struct bContext *C,
                                      struct Main *UNUSED(bmain),
                                      UndoStep *us_p)
 {
+  if (C == NULL) {
+    return false;
+  }
+
   TextUndoStep *us = (TextUndoStep *)us_p;
 
   Text *text = us->text_ref.ptr;
   BLI_assert(text == CTX_data_edit_text(C));
-  UNUSED_VARS_NDEBUG(C);
 
   us->step.data_size += text_undosys_step_encode_to_state(&us->states[1], text);
 
@@ -260,7 +263,7 @@ void ED_text_undosys_type(UndoType *ut)
 
   ut->step_foreach_ID_ref = text_undosys_foreach_ID_ref;
 
-  ut->use_context = false;
+  ut->use_context_for_encode = false;
 
   ut->step_size = sizeof(TextUndoStep);
 }
diff --git a/source/blender/editors/undo/memfile_undo.c b/source/blender/editors/undo/memfile_undo.c
index 4fded419b5b..456458173ce 100644
--- a/source/blender/editors/undo/memfile_undo.c
+++ b/source/blender/editors/undo/memfile_undo.c
@@ -282,7 +282,7 @@ void ED_memfile_undosys_type(UndoType *ut)
   ut->step_decode = memfile_undosys_step_decode;
   ut->step_free = memfile_undosys_step_free;
 
-  ut->use_context = true;
+  ut->use_context_for_encode = true;
 
   ut->step_size = sizeof(MemFileUndoStep);
 }



More information about the Bf-blender-cvs mailing list