Refactor: Move contextual init before socket declaration

Currently, the standard init function is called before socket
declaration, but the contextual init function is called after, which is
problematic if the declaration depends on the initialization step. This
patch moves the contextual init function to be called before declaration
just like the standard init function.

This is needed when moving the File Output node to use socket
declaration.

Pull Request: https://projects.blender.org/blender/blender/pulls/141203
This commit is contained in:
Omar Emara
2025-06-30 18:47:09 +02:00
committed by Omar Emara
parent b7f1aa4a41
commit fd24e1001a

View File

@@ -1823,6 +1823,15 @@ static void node_init(const bContext *C, bNodeTree *ntree, bNode *node)
ntype->initfunc(ntree, node);
}
if (ntype->initfunc_api) {
PointerRNA ptr = RNA_pointer_create_discrete(&ntree->id, &RNA_Node, node);
/* XXX WARNING: context can be nullptr in case nodes are added in do_versions.
* Delayed init is not supported for nodes with context-based `initfunc_api` at the moment. */
BLI_assert(C != nullptr);
ntype->initfunc_api(C, &ptr);
}
if (ntree->typeinfo && ntree->typeinfo->node_add_init) {
ntree->typeinfo->node_add_init(ntree, node);
}
@@ -1835,15 +1844,6 @@ static void node_init(const bContext *C, bNodeTree *ntree, bNode *node)
id_us_plus(node->id);
}
if (ntype->initfunc_api) {
PointerRNA ptr = RNA_pointer_create_discrete(&ntree->id, &RNA_Node, node);
/* XXX WARNING: context can be nullptr in case nodes are added in do_versions.
* Delayed init is not supported for nodes with context-based `initfunc_api` at the moment. */
BLI_assert(C != nullptr);
ntype->initfunc_api(C, &ptr);
}
node->flag |= NODE_INIT;
}