Fix T102554: Crash when Use Nodes is enabled

Blender crashes when enabling Use Nodes after the viewport compositor is
already enabled.

This happens because the active viewer key is not yet initialized for the
node tree at this point, which eventually leads to a nullptr.

This patch fixes that by returning the root context in case the active
viewer key is not yet initialized.
This commit is contained in:
Omar Emara 2022-11-17 11:12:41 +02:00
parent 9a09adb7af
commit dd260d2f03
Notes: blender-bot 2023-02-13 14:00:49 +01:00
Referenced by issue #102577, Cannot build Blender on macOS on M1/arm64: 'Mac OSX requires pre-compiled libs'
Referenced by issue #102554, Regression: Crash when Use Nodes is enabled after enabling the viewport compositor
1 changed files with 6 additions and 0 deletions

View File

@ -60,6 +60,12 @@ static const DTreeContext *find_active_context_recursive(const DTreeContext *con
* instance of the node group. */
static const DTreeContext *find_active_context(const DerivedNodeTree &tree)
{
/* If the active viewer key is NODE_INSTANCE_KEY_NONE, that means it is not yet initialized and
* we return the root context in that case. See the find_active_context_recursive function. */
if (tree.root_context().btree().active_viewer_key.value == NODE_INSTANCE_KEY_NONE.value) {
return &tree.root_context();
}
/* The root context has an instance key of NODE_INSTANCE_KEY_BASE by definition. */
return find_active_context_recursive(&tree.root_context(), NODE_INSTANCE_KEY_BASE);
}