Fix #125419: crash when loading baked data with empty instances
The problem was the automatic instance deduplication. There were two instance references before baking, both of which were referenced by instances. When loading the bake, they were deduplicated, so there was only one geometry, but the instances still referenced two. The fix is to not do deduplication when loading instances from a bake.
This commit is contained in:
@@ -149,6 +149,10 @@ class Instances {
|
||||
* Otherwise a new handle is added.
|
||||
*/
|
||||
int add_reference(const InstanceReference &reference);
|
||||
/**
|
||||
* Same as above, but does not deduplicate with existing references.
|
||||
*/
|
||||
int add_new_reference(const InstanceReference &reference);
|
||||
std::optional<int> find_reference_handle(const InstanceReference &query);
|
||||
/**
|
||||
* Add a reference to the instance reference with an index specified by the #instance_handle
|
||||
|
||||
@@ -849,7 +849,7 @@ static std::unique_ptr<Instances> try_load_instances(const DictionaryValue &io_g
|
||||
if (io_reference) {
|
||||
reference_geometry = load_geometry(*io_reference, blob_reader, blob_sharing);
|
||||
}
|
||||
instances->add_reference(std::move(reference_geometry));
|
||||
instances->add_new_reference(std::move(reference_geometry));
|
||||
}
|
||||
|
||||
MutableAttributeAccessor attributes = instances->attributes_for_write();
|
||||
|
||||
@@ -247,6 +247,11 @@ int Instances::add_reference(const InstanceReference &reference)
|
||||
if (std::optional<int> handle = this->find_reference_handle(reference)) {
|
||||
return *handle;
|
||||
}
|
||||
return this->add_new_reference(reference);
|
||||
}
|
||||
|
||||
int Instances::add_new_reference(const InstanceReference &reference)
|
||||
{
|
||||
this->tag_reference_handles_changed();
|
||||
return references_.append_and_get_index(reference);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user