Commit: 468f43c7a6e96ba55d72564a8f11d60fc8984d33 Author: Hans Goudey Date: Wed Dec 14 16:42:48 2022 -0600 Branches: geometry-nodes-simulation https://developer.blender.org/rB468f43c7a6e96ba55d72564a8f11d60fc8984d33
Fix simulation =================================================================== M source/blender/blenkernel/intern/node.cc M source/blender/makesdna/DNA_node_types.h M source/blender/nodes/NOD_node_declaration.hh M source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc M source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc =================================================================== diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index e52f8fe2f1e..3e350fbb80a 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -1124,12 +1124,12 @@ static void node_init(const bContext *C, bNodeTree *ntree, bNode *node) BLI_strncpy(node->name, DATA_(ntype->ui_name), NODE_MAXSTR); nodeUniqueName(ntree, node); - node_add_sockets_from_type(ntree, node, ntype); - if (ntype->initfunc != nullptr) { ntype->initfunc(ntree, node); } + node_add_sockets_from_type(ntree, node, ntype); + if (ntree->typeinfo && ntree->typeinfo->node_add_init) { ntree->typeinfo->node_add_init(ntree, node); } diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index ba2d63644ef..eaf0ea9e6ba 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -1594,7 +1594,7 @@ typedef struct NodeGeometrySimulationOutput { int state_items_num; int8_t use_persistent_cache; - int _pad[3]; + char _pad[3]; } NodeGeometrySimulationOutput; typedef struct NodeGeometryDistributePointsInVolume { diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh index 9c5362a64bc..c28f7525245 100644 --- a/source/blender/nodes/NOD_node_declaration.hh +++ b/source/blender/nodes/NOD_node_declaration.hh @@ -527,7 +527,7 @@ inline NodeDeclarationBuilder::NodeDeclarationBuilder(NodeDeclaration &declarati inline NodeDeclarationBuilder::NodeDeclarationBuilder(const bNode &node, NodeDeclaration &declaration) - : node_(&node), declaration_(declaration) + : declaration_(declaration), node_(&node) { } diff --git a/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc b/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc index aa543be2f40..4a785d9fae8 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc @@ -22,6 +22,8 @@ static void node_declare(NodeDeclarationBuilder &b) const bNode &node = b.node(); const NodeGeometrySimulationInput &storage = node_storage(node); const int32_t sim_output_node_id = storage.output_node_id; + /* TODO: Add node tree and ndoe as arguments to new dynamic declaration function. */ + node.owner_tree().ensure_topology_cache(); const bNode *sim_output_node = node.owner_tree().node_by_id(sim_output_node_id); if (!sim_output_node) { return; diff --git a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc index 83db79cdcf3..ab330ee65c4 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc @@ -58,28 +58,35 @@ static void node_declare(NodeDeclarationBuilder &b) static void node_init(bNodeTree * /*tree*/, bNode *node) { - NodeGeometrySimulationOutput *data = MEM_cnew<NodeGeometrySimulationOutput>(__func__); - data->state_items = MEM_cnew_array<SimulationStateItem>(1, __func__); - data->state_items[0].name = BLI_strdup(DATA_("Geometry")); - data->state_items[0].data_type = SOCK_GEOMETRY; - data->state_items_num = 1; - data->use_persistent_cache = false; - node->storage = data; + NodeGeometrySimulationOutput *storage = MEM_cnew<NodeGeometrySimulationOutput>(__func__); + storage->state_items = MEM_cnew_array<SimulationStateItem>(1, __func__); + storage->state_items[0].name = BLI_strdup(DATA_("Geometry")); + storage->state_items[0].data_type = SOCK_GEOMETRY; + storage->state_items_num = 1; + storage->use_persistent_cache = false; + node->storage = storage; } static void node_free_storage(bNode *node) { NodeGeometrySimulationOutput &storage = node_storage(*node); + for (SimulationStateItem &item : MutableSpan(storage.state_items, storage.state_items_num)) { + MEM_SAFE_FREE(item.name); + } MEM_SAFE_FREE(storage.state_items); } -void node_copy_storage(bNodeTree * /*dest_ntree*/, bNode *dst_node, const bNode *src_node) +static void node_copy_storage(bNodeTree * /*dest_ntree*/, bNode *dst_node, const bNode *src_node) { const NodeGeometrySimulationOutput &src = node_storage(*src_node); - NodeGeometrySimulationOutput &dst = node_storage(*dst_node); - MEM_SAFE_FREE(dst.state_items); - dst.state_items = MEM_cnew_array<SimulationStateItem>(src.state_items_num, __func__); - dst.state_items_num = src.state_items_num; + NodeGeometrySimulationOutput *dst = MEM_cnew<NodeGeometrySimulationOutput>(__func__); + MEM_SAFE_FREE(dst->state_items); + dst->state_items = MEM_cnew_array<SimulationStateItem>(src.state_items_num, __func__); + dst->state_items_num = src.state_items_num; + for (const int i : IndexRange(dst->state_items_num)) { + dst->state_items[i].name = static_cast<char *>(MEM_dupallocN(src.state_items[i].name)); + } + dst_node->storage = dst; } static void node_geo_exec(GeoNodeExecParams params) _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs