[Bf-blender-cvs] [4cdb4b9532c] master: Fix T64161: Crashing using undo and multiple windows

Sergey Sharybin noreply at git.blender.org
Mon May 6 16:40:29 CEST 2019


Commit: 4cdb4b9532c8151ec9f1caba7a764c4f5a334f30
Author: Sergey Sharybin
Date:   Mon May 6 16:38:17 2019 +0200
Branches: master
https://developer.blender.org/rB4cdb4b9532c8151ec9f1caba7a764c4f5a334f30

Fix T64161: Crashing using undo and multiple windows

It is possible that dependency graph was not yet initialized,
so need to do NULL pointer check.

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

M	source/blender/depsgraph/DEG_depsgraph_query.h
M	source/blender/depsgraph/intern/depsgraph_query.cc
M	source/blender/windowmanager/intern/wm_event_system.c

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

diff --git a/source/blender/depsgraph/DEG_depsgraph_query.h b/source/blender/depsgraph/DEG_depsgraph_query.h
index 3030bfb28b3..a7ada7f3cd0 100644
--- a/source/blender/depsgraph/DEG_depsgraph_query.h
+++ b/source/blender/depsgraph/DEG_depsgraph_query.h
@@ -79,6 +79,16 @@ void DEG_get_customdata_mask_for_object(const struct Depsgraph *graph,
  * one. Assert will happen if it's not. */
 struct Scene *DEG_get_evaluated_scene(const struct Depsgraph *graph);
 
+/* Similar to DEG_get_evaluated_scene(), but allows to access non-fully evaluated pointer without
+ * causing asserts or crashes. Works the following way:
+ *  - If the scene was never evaluated NULL returned.
+ *  - Otherwise the last known state of the scene is returned.
+ *
+ * Use in exceptional case if it's absolutely must to.
+ *
+ * Allows to pass depsgraph == NULL, wil lreturn NULL in that case. */
+struct Scene *DEG_get_evaluated_scene_if_exists(const struct Depsgraph *graph);
+
 /* Get view layer at its evaluated state.
  * This is a shortcut for accessing active view layer from evaluated scene. */
 struct ViewLayer *DEG_get_evaluated_view_layer(const struct Depsgraph *graph);
diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc b/source/blender/depsgraph/intern/depsgraph_query.cc
index a653366a588..75eabc6930f 100644
--- a/source/blender/depsgraph/intern/depsgraph_query.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query.cc
@@ -152,6 +152,19 @@ Scene *DEG_get_evaluated_scene(const Depsgraph *graph)
   return scene_cow;
 }
 
+Scene *DEG_get_evaluated_scene_if_exists(const Depsgraph *graph)
+{
+  if (graph == NULL) {
+    return NULL;
+  }
+  const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
+  Scene *scene_cow = deg_graph->scene_cow;
+  if (scene_cow == NULL || !DEG::deg_copy_on_write_is_expanded(&scene_cow->id)) {
+    return NULL;
+  }
+  return scene_cow;
+}
+
 ViewLayer *DEG_get_evaluated_view_layer(const Depsgraph *graph)
 {
   const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 6745af25dcd..742fbd4b903 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -3097,9 +3097,9 @@ void wm_event_do_handlers(bContext *C)
       CTX_data_scene_set(C, scene);
 
       Depsgraph *depsgraph = CTX_data_depsgraph(C);
-      Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
+      Scene *scene_eval = DEG_get_evaluated_scene_if_exists(depsgraph);
 
-      if (scene) {
+      if (scene_eval) {
         const int is_playing_sound = BKE_sound_scene_playing(scene_eval);
 
         if (is_playing_sound != -1) {



More information about the Bf-blender-cvs mailing list