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.
This commit is contained in:
Omar Emara 2022-12-20 10:09:25 +02:00
parent edb5dcaa31
commit 105c0aa5b6
Notes: blender-bot 2023-02-14 06:00:50 +01:00
Referenced by issue #103064, Realtime Compositor: Crash on undo after dissolve node
3 changed files with 8 additions and 14 deletions

View File

@ -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

View File

@ -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;

View File

@ -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