[Bf-blender-cvs] [3566b81c8bf] master: Refactor access to dependency graph

Sergey Sharybin noreply at git.blender.org
Wed Jul 31 16:55:18 CEST 2019


Commit: 3566b81c8bfa8c69d542a5de29ecb8d5af3ccb3d
Author: Sergey Sharybin
Date:   Thu Jul 25 16:36:22 2019 +0200
Branches: master
https://developer.blender.org/rB3566b81c8bfa8c69d542a5de29ecb8d5af3ccb3d

Refactor access to dependency graph

This change ensures that operators which needs access to evaluated data
first makes sure there is a dependency graph.

Other accesses to the dependency graph made it more explicit about
whether they just need a valid dependency graph pointer or whether they
expect the graph to be already evaluated.

This replaces OPTYPE_USE_EVAL_DATA which is now removed.

Some general rules about usage of accessors:

- Drawing is expected to happen from a fully evaluated dependency graph.
  There is now a function to access it, which will in the future control
  that dependency graph is actually evaluated.

  This check is not yet done because there are some things to be taken
  care about first: for example, post-update hooks might leave scene in
  a state where something is still tagged for update.

- All operators which needs to access evaluated state must use
  CTX_data_ensure_evaluated_depsgraph().

  This function replaces OPTYPE_USE_EVAL_DATA.

  The call is generally to be done in the very beginning of the
  operator, prior other logic (unless this is some comprehensive
  operator which might or might not need access to an evaluated state).

  This call is never to be used from a loop.

  If some utility function requires evaluated state of dependency graph
  the graph is to be passed as an explicit argument. This way it is
  clear that no evaluation happens in a loop or something like this.

- All cases which needs to know dependency graph pointer, but which
  doesn't want to actually evaluate it can use old-style function
  CTX_data_depsgraph_pointer(), assuming that underlying code will
  ensure dependency graph is evaluated prior to accessing it.

- The new functions are replacing OPTYPE_USE_EVAL_DATA, so now it is
  explicit and local about where dependency graph is being ensured.

This commit also contains some fixes of wrong usage of evaluation
functions on original objects. Ideally should be split out, but in
reality with all the APIs being renamed is quite tricky.

Fixes T67454: Blender crash on rapid undo and select

Speculation here is that sometimes undo and selection operators are
sometimes handled in the same event loop iteration, which leaves
non-evaluated dependency graph.

Fixes T67973: Crash on Fix Deforms operator
Fixes T67902: Crash when undo a loop cut

Reviewers: brecht

Reviewed By: brecht

Subscribers: lichtwerk

Maniphest Tasks: T67454

Differential Revision: https://developer.blender.org/D5343

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

M	source/blender/blenkernel/BKE_context.h
M	source/blender/blenkernel/intern/context.c
M	source/blender/draw/intern/draw_manager.c
M	source/blender/editors/armature/pose_edit.c
M	source/blender/editors/armature/pose_lib.c
M	source/blender/editors/armature/pose_slide.c
M	source/blender/editors/armature/pose_transform.c
M	source/blender/editors/curve/editcurve.c
M	source/blender/editors/curve/editcurve_paint.c
M	source/blender/editors/curve/editfont.c
M	source/blender/editors/gizmo_library/gizmo_library_presets.c
M	source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c
M	source/blender/editors/gpencil/annotate_paint.c
M	source/blender/editors/gpencil/drawgpencil.c
M	source/blender/editors/gpencil/gpencil_armature.c
M	source/blender/editors/gpencil/gpencil_brush.c
M	source/blender/editors/gpencil/gpencil_convert.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_select.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_mesh.h
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/interface/interface_eyedropper_depth.c
M	source/blender/editors/io/io_cache.c
M	source/blender/editors/mask/mask_add.c
M	source/blender/editors/mask/mask_ops.c
M	source/blender/editors/mesh/editface.c
M	source/blender/editors/mesh/editmesh_extrude.c
M	source/blender/editors/mesh/editmesh_knife_project.c
M	source/blender/editors/mesh/editmesh_loopcut.c
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/editors/mesh/meshtools.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/object/object_constraint.c
M	source/blender/editors/object/object_data_transfer.c
M	source/blender/editors/object/object_edit.c
M	source/blender/editors/object/object_gpencil_modifier.c
M	source/blender/editors/object/object_hook.c
M	source/blender/editors/object/object_modes.c
M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/object/object_relations.c
M	source/blender/editors/object/object_transform.c
M	source/blender/editors/object/object_vgroup.c
M	source/blender/editors/physics/dynamicpaint_ops.c
M	source/blender/editors/physics/particle_edit.c
M	source/blender/editors/physics/particle_object.c
M	source/blender/editors/physics/physics_fluid.c
M	source/blender/editors/physics/physics_pointcache.c
M	source/blender/editors/physics/rigidbody_object.c
M	source/blender/editors/render/render_internal.c
M	source/blender/editors/render/render_opengl.c
M	source/blender/editors/render/render_shading.c
M	source/blender/editors/render/render_update.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/sculpt_paint/paint_hide.c
M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/paint_mask.c
M	source/blender/editors/sculpt_paint/paint_utils.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/editors/sound/sound_ops.c
M	source/blender/editors/space_clip/space_clip.c
M	source/blender/editors/space_clip/tracking_ops_orient.c
M	source/blender/editors/space_image/space_image.c
M	source/blender/editors/space_outliner/outliner_select.c
M	source/blender/editors/space_sequencer/sequencer_buttons.c
M	source/blender/editors/space_sequencer/sequencer_draw.c
M	source/blender/editors/space_sequencer/sequencer_edit.c
M	source/blender/editors/space_sequencer/sequencer_view.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_fly.c
M	source/blender/editors/space_view3d/view3d_gizmo_camera.c
M	source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c
M	source/blender/editors/space_view3d/view3d_gizmo_ruler.c
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/editors/space_view3d/view3d_snap.c
M	source/blender/editors/space_view3d/view3d_view.c
M	source/blender/editors/space_view3d/view3d_walk.c
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_gizmo_3d.c
M	source/blender/editors/undo/ed_undo.c
M	source/blender/editors/util/ed_util.c
M	source/blender/editors/uvedit/uvedit_ops.c
M	source/blender/makesrna/intern/rna_context.c
M	source/blender/makesrna/intern/rna_layer.c
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/makesrna/intern/rna_object_api.c
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_files.c
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index 0d2998cc51e..53976b4c1ad 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -318,7 +318,14 @@ int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list);
  * evaluated data points of view.
  *
  * NOTE: Can not be used if access to a fully evaluated datablock is needed. */
-struct Depsgraph *CTX_data_depsgraph(const bContext *C);
+struct Depsgraph *CTX_data_depsgraph_pointer(const bContext *C);
+
+/* Get dependency graph which is expected to be fully evaluated.
+ *
+ * In the release builds it is the same as CTX_data_depsgraph_pointer(). In the debug builds extra
+ * sanity checks are done. Additionally, this provides more semantic meaning to what is exactly
+ * expected to happen. */
+struct Depsgraph *CTX_data_expect_evaluated_depsgraph(const bContext *C);
 
 /* Gets fully updated and evaluated dependency graph.
  *
@@ -326,7 +333,7 @@ struct Depsgraph *CTX_data_depsgraph(const bContext *C);
  *
  * NOTE: Will be expensive if there are relations or objects tagged for update.
  * NOTE: If there are pending updates depsgraph hooks will be invoked. */
-struct Depsgraph *CTX_data_evaluated_depsgraph(const bContext *C);
+struct Depsgraph *CTX_data_ensure_evaluated_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.
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 4ae87713aa5..2cb98d8d90b 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -1348,7 +1348,7 @@ int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list)
   return ctx_data_collection_get(C, "editable_gpencil_strokes", list);
 }
 
-Depsgraph *CTX_data_depsgraph(const bContext *C)
+Depsgraph *CTX_data_depsgraph_pointer(const bContext *C)
 {
   Scene *scene = CTX_data_scene(C);
   ViewLayer *view_layer = CTX_data_view_layer(C);
@@ -1361,9 +1361,18 @@ Depsgraph *CTX_data_depsgraph(const bContext *C)
   return depsgraph;
 }
 
-Depsgraph *CTX_data_evaluated_depsgraph(const bContext *C)
+Depsgraph *CTX_data_expect_evaluated_depsgraph(const bContext *C)
 {
-  Depsgraph *depsgraph = CTX_data_depsgraph(C);
+  Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
+  /* TODO(sergey): Assert that the dependency graph is fully evaluated.
+   * Note that first the depsgraph and scene post-eval hooks needs to run extra round of updates
+   * first to make check here really reliable. */
+  return depsgraph;
+}
+
+Depsgraph *CTX_data_ensure_evaluated_depsgraph(const bContext *C)
+{
+  Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
   Main *bmain = CTX_data_main(C);
   BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
   return depsgraph;
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index af61063335b..cb03d51e090 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -1528,7 +1528,7 @@ void DRW_notify_view_update(const DRWUpdateContext *update_ctx)
  * for each relevant engine / mode engine. */
 void DRW_draw_view(const bContext *C)
 {
-  Depsgraph *depsgraph = CTX_data_depsgraph(C);
+  Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C);
   ARegion *ar = CTX_wm_region(C);
   View3D *v3d = CTX_wm_view3d(C);
   Scene *scene = DEG_get_evaluated_scene(depsgraph);
diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c
index 5daf6b584e5..3fd74cc3ca7 100644
--- a/source/blender/editors/armature/pose_edit.c
+++ b/source/blender/editors/armature/pose_edit.c
@@ -195,7 +195,9 @@ void ED_pose_recalculate_paths(bContext *C, Scene *scene, Object *ob, bool curre
   }
 
   Main *bmain = CTX_data_main(C);
-  Depsgraph *depsgraph = CTX_data_depsgraph(C);
+  /* NOTE: Dependency graph will be evaluated at all the frames, but we first need to access some
+   * nested pointers, like animation data. */
+  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
   ListBase targets = {NULL, NULL};
   bool free_depsgraph = false;
 
diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c
index 3407b3e6b7f..4cda7f264aa 100644
--- a/source/blender/editors/armature/pose_lib.c
+++ b/source/blender/editors/armature/pose_lib.c
@@ -1731,9 +1731,6 @@ static void poselib_preview_cleanup(bContext *C, wmOperator *op)
     if (IS_AUTOKEY_MODE(scene, NORMAL)) {
       // remake_action_ipos(ob->action);
     }
-    else {
-      BKE_pose_where_is(CTX_data_depsgraph(C), scene, ob);
-    }
   }
 
   /* Request final redraw of the view. */
diff --git a/source/blender/editors/armature/pose_slide.c b/source/blender/editors/armature/pose_slide.c
index 4c5a42cade6..ae9401fb430 100644
--- a/source/blender/editors/armature/pose_slide.c
+++ b/source/blender/editors/armature/pose_slide.c
@@ -1373,7 +1373,7 @@ void POSE_OT_push(wmOperatorType *ot)
   ot->poll = ED_operator_posemode;
 
   /* flags */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA;
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
 
   /* Properties */
   pose_slide_opdef_properties(ot);
@@ -1435,7 +1435,7 @@ void POSE_OT_relax(wmOperatorType *ot)
   ot->poll = ED_operator_posemode;
 
   /* flags */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA;
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
 
   /* Properties */
   pose_slide_opdef_properties(ot);
@@ -1496,7 +1496,7 @@ void POSE_OT_push_rest(wmOperatorType *ot)
   ot->poll = ED_operator_posemode;
 
   /* flags */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA;
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
 
   /* Properties */
   pose_slide_opdef_properties(ot);
@@ -1558,7 +1558,7 @@ void POSE_OT_relax_rest(wmOperatorType *ot)
   ot->poll = ED_operator_posemode;
 
   /* flags */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA;
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
 
   /* Properties */
   pose_slide_opdef_properties(ot);
@@ -1620,7 +1620,7 @@ void POSE_OT_breakdown(wmOperatorType *ot)
   ot->poll = ED_operator_posemode;
 
   /* flags */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA;
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
 
   /* Properties */
   pose_slide_opdef_properties(ot);
@@ -2025,7 +2025,7 @@ void POSE_OT_propagate(wmOperatorType *ot)
   ot->poll = ED_operator_posemode; /* XXX: needs selected bones! */
 
   /* flag */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
   /* properties */
   /* TODO: add "fade out" control for tapering off amount of propagation as time goes by? */
diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c
index 224bbb1d79f..854fb237929 100644
--- a/source/blender/editors/armature/pose_transform.c
+++ b/source/blender/editors/armature/pose_transform.c
@@ -71,7 +71,15 @@
  * that are bone-parented to armature */
 static void applyarmature_fix_boneparents(const bContext *C, Scene *scene, Object *armob)
 {
-  Depsgraph *depsgraph = CTX_data_depsgraph(C);
+  /* Depsgraph has been ensured to be evaluated at the beginning of the operator.
+   *
+   * Must not evaluate depsgraph here yet, since this will ruin object matrix which we want to
+   * preserve after other changes has been done in the operator.
+   *
+   * TODO(sergey): This seems very similar to `ignore_parent_tx()`, which was now ensured to work
+   * quite reliably. Can we de-duplicate the code? Or at least verify we don't need an extra logic
+   * in this function. */
+  Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
   Main *bmain = CTX_data_main(C);
   Object workob, *ob;
 
@@ -318,7 +326,7 @@ static void applyarmature_process_selected_rec(bArmature *arm,
 static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op)
 {
   Main *bmain = CTX_data_main(C);
-  Depsgraph *depsgraph = CTX_data_depsgraph(C);
+  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
   Scene *scene = CTX_data_scene(C);
   // must be active object, not edit-object
   Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
@@ -422,7 +430,7 @@ void POSE_OT_armature_apply(wmOperatorType *ot)
   ot->ui = apply_armature_pose2bones_ui;
 
   /* flags */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA;
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
   RNA_def_boolean(ot->srna,
                   "selected",
@@ -436,7 +444,7 @@ static int pose_visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op))
 {
   ViewLayer *view_layer = CTX_data_view_layer(C);
   View3D *v3d = CTX_wm_view3d(C);
-  Depsgraph *depsgraph = CTX_data_depsgraph(C);
+  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
 
   FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob) {
     /* loop over all selected pchans
@@ -1026,6 +1034,7 @@ static int pose_clear_transform_generic_exec(bContext *C,
                                              void (*clear_func)(bPoseChannel *),
                                              const char default_ksName[])
 {
+  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
   Scene *scene = CTX_data_scene(C);
   bool changed_multi = false;
 
@@ -1041,8 +1050,8 @@ static int pose_clear_transform_generic_exec(bContext *C,
   ViewLayer *view_layer = CTX_data_view_layer(C);
   View3D *v3d = CTX_wm_view3d(C);
   FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob_iter) {
-    Object *ob_eval = DEG_get_evaluated_object(
-        CTX_data_depsgraph(C), ob_iter);  // XXX: UGLY HACK (for autokey + clear transforms)
+    // XXX: UGLY HACK (for autokey + clear transforms)
+    Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob_iter);
     Lis

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list