From ce67a72c0d322814eea72b22d671d902ab9199cc Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 30 May 2023 10:18:48 +0200 Subject: [PATCH] fix --- .../geometry/nodes/node_geo_simulation_output.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 8797abc14b9..bd319015543 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc @@ -131,17 +131,33 @@ const CPPType &get_simulation_item_cpp_type(const NodeSimulationItem &item) return get_simulation_item_cpp_type(eNodeSocketDatatype(item.socket_type)); } +static void remove_materials(Material ***materials, short *materials_num) +{ + MEM_SAFE_FREE(*materials); + *materials_num = 0; +} + +/** + * Removess parts of the geometry that can't be stored in the simulation state: + * - Anonymous attributes can't be stored because it is not known which of them will or will not be + * used in the future. + * - Materials can't be stored directly, because they are linked ID data blocks that can't be + * restored from baked data currently. + */ static void cleanup_geometry_for_simulation_state(GeometrySet &main_geometry) { main_geometry.modify_geometry_sets([&](GeometrySet &geometry) { if (Mesh *mesh = geometry.get_mesh_for_write()) { mesh->attributes_for_write().remove_anonymous(); + remove_materials(&mesh->mat, &mesh->totcol); } if (Curves *curves = geometry.get_curves_for_write()) { curves->geometry.wrap().attributes_for_write().remove_anonymous(); + remove_materials(&curves->mat, &curves->totcol); } if (PointCloud *pointcloud = geometry.get_pointcloud_for_write()) { pointcloud->attributes_for_write().remove_anonymous(); + remove_materials(&pointcloud->mat, &pointcloud->totcol); } if (bke::Instances *instances = geometry.get_instances_for_write()) { instances->attributes_for_write().remove_anonymous(); -- 2.30.2