Fix T91767: crash when instancing geometry coming from modifier

The issue was that the `GeometrySet` that comes from the modifier does
not have full ownership of the mesh for legacy reasons to avoid copies.
Calling `ensure_owns_direct_data` makes sure that the geometry set
actually owns the geometry so that it can be instanced.
This commit is contained in:
2021-09-29 10:55:32 +02:00
parent f51bef75f4
commit 24a965bb16

View File

@@ -57,10 +57,9 @@ static void geo_node_instance_on_points_declare(NodeDeclarationBuilder &b)
static void add_instances_from_component(InstancesComponent &dst_component,
const GeometryComponent &src_component,
const GeometrySet &instance,
const GeoNodeExecParams &params)
{
GeometrySet instance = params.get_input<GeometrySet>("Instance");
const AttributeDomain domain = ATTR_DOMAIN_POINT;
const int domain_size = src_component.attribute_domain_size(domain);
@@ -163,23 +162,27 @@ static void add_instances_from_component(InstancesComponent &dst_component,
static void geo_node_instance_on_points_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Points");
GeometrySet instance = params.get_input<GeometrySet>("Instance");
instance.ensure_owns_direct_data();
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>();
if (geometry_set.has<MeshComponent>()) {
add_instances_from_component(
instances, *geometry_set.get_component_for_read<MeshComponent>(), params);
instances, *geometry_set.get_component_for_read<MeshComponent>(), instance, params);
geometry_set.remove(GEO_COMPONENT_TYPE_MESH);
}
if (geometry_set.has<PointCloudComponent>()) {
add_instances_from_component(
instances, *geometry_set.get_component_for_read<PointCloudComponent>(), params);
add_instances_from_component(instances,
*geometry_set.get_component_for_read<PointCloudComponent>(),
instance,
params);
geometry_set.remove(GEO_COMPONENT_TYPE_POINT_CLOUD);
}
if (geometry_set.has<CurveComponent>()) {
add_instances_from_component(
instances, *geometry_set.get_component_for_read<CurveComponent>(), params);
instances, *geometry_set.get_component_for_read<CurveComponent>(), instance, params);
geometry_set.remove(GEO_COMPONENT_TYPE_CURVE);
}
/* Unused references may have been added above. Remove those now so that other nodes don't