[Bf-blender-cvs] [105c0aa5b6d] master: Fix T103064: Realtime Compositor crashes on undo

Omar Emara noreply at git.blender.org
Tue Dec 20 09:13:06 CET 2022


Commit: 105c0aa5b6dea92751e6ee459d91a79f7d6b2240
Author: Omar Emara
Date:   Tue Dec 20 10:09:25 2022 +0200
Branches: master
https://developer.blender.org/rB105c0aa5b6dea92751e6ee459d91a79f7d6b2240

Fix T103064: Realtime Compositor crashes on undo

The Realtime Compositor crashes on undo after an operation like Dissolve
node.

The compositor evaluator stored a reference to the compositor node tree
assuming that it will always be valid. This is not guaranteed, however,
and changes to the node tree can invalidate that reference. So we get
the node tree from the context directly every time to fix the crash.

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

M	source/blender/compositor/realtime_compositor/COM_evaluator.hh
M	source/blender/compositor/realtime_compositor/intern/evaluator.cc
M	source/blender/draw/engines/compositor/compositor_engine.cc

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

diff --git a/source/blender/compositor/realtime_compositor/COM_evaluator.hh b/source/blender/compositor/realtime_compositor/COM_evaluator.hh
index 258a2a038c4..c8e953da268 100644
--- a/source/blender/compositor/realtime_compositor/COM_evaluator.hh
+++ b/source/blender/compositor/realtime_compositor/COM_evaluator.hh
@@ -102,8 +102,9 @@ class Evaluator {
  private:
   /* A reference to the compositor context. */
   Context &context_;
-  /* A reference to the compositor node tree. */
-  bNodeTree &node_tree_;
+  /* A derived node tree representing the compositor node tree. This is constructed when the node
+   * tree is compiled and reset when the evaluator is reset, so it gets reconstructed every time
+   * the node tree changes. */
   std::unique_ptr<DerivedNodeTree> derived_node_tree_;
   /* The compiled operations stream. This contains ordered pointers to the operations that were
    * compiled. This is initialized when the node tree is compiled and freed when the evaluator
@@ -116,8 +117,8 @@ class Evaluator {
   bool is_compiled_ = false;
 
  public:
-  /* Construct an evaluator from a compositor node tree and a context. */
-  Evaluator(Context &context, bNodeTree &node_tree);
+  /* Construct an evaluator from a context. */
+  Evaluator(Context &context);
 
   /* Evaluate the compositor node tree. If the node tree is already compiled into an operations
    * stream, that stream will be evaluated directly. Otherwise, the node tree will be compiled and
diff --git a/source/blender/compositor/realtime_compositor/intern/evaluator.cc b/source/blender/compositor/realtime_compositor/intern/evaluator.cc
index 1cd7d4f8951..1b52e1d381d 100644
--- a/source/blender/compositor/realtime_compositor/intern/evaluator.cc
+++ b/source/blender/compositor/realtime_compositor/intern/evaluator.cc
@@ -21,8 +21,7 @@ namespace blender::realtime_compositor {
 
 using namespace nodes::derived_node_tree_types;
 
-Evaluator::Evaluator(Context &context, bNodeTree &node_tree)
-    : context_(context), node_tree_(node_tree)
+Evaluator::Evaluator(Context &context) : context_(context)
 {
 }
 
@@ -67,7 +66,7 @@ bool Evaluator::validate_node_tree()
 
 void Evaluator::compile_and_evaluate()
 {
-  derived_node_tree_ = std::make_unique<DerivedNodeTree>(node_tree_);
+  derived_node_tree_ = std::make_unique<DerivedNodeTree>(*context_.get_scene()->nodetree);
 
   if (!validate_node_tree()) {
     return;
diff --git a/source/blender/draw/engines/compositor/compositor_engine.cc b/source/blender/draw/engines/compositor/compositor_engine.cc
index 3b7378f280b..03ef0be81b4 100644
--- a/source/blender/draw/engines/compositor/compositor_engine.cc
+++ b/source/blender/draw/engines/compositor/compositor_engine.cc
@@ -90,7 +90,7 @@ class Engine {
  public:
   Engine(char *info_message)
       : context_(texture_pool_, info_message),
-        evaluator_(context_, node_tree()),
+        evaluator_(context_),
         last_viewport_size_(context_.get_output_size())
   {
   }
@@ -124,12 +124,6 @@ class Engine {
       evaluator_.reset();
     }
   }
-
-  /* Get a reference to the compositor node tree. */
-  static bNodeTree &node_tree()
-  {
-    return *DRW_context_state_get()->scene->nodetree;
-  }
 };
 
 }  // namespace blender::draw::compositor



More information about the Bf-blender-cvs mailing list