Fix #118307: Outliner crash with additional constraint on overridden bone

Since `IDOverrideLibraryProperty` apparently stores its rna_path with
string-based collection keys, we have to make sure we also use string-
based keys elsewhere in `OverrideRNAPathTreeBuilder::build_path` and
down the line, otherwise:
- we get duplicate collection entries ("pose.bones[1].constraints" vs.
"pose.bones["Bone.001"].constraints")
- crashes may occur (we are reading on an already freed `TreeElement`
see #118307 for ASAN output)

So now make sure we are using string-based collection keys when we can
so the TreeElements match /and dont get duplicated).

NOTE: the duplication of entries came with 67b92418ee

Pull Request: https://projects.blender.org/blender/blender/pulls/118573
This commit is contained in:
Philipp Oeser
2024-02-23 09:15:37 +01:00
committed by Philipp Oeser
parent 3e232aaac1
commit 8b44c62ce7

View File

@@ -321,6 +321,7 @@ void OverrideRNAPathTreeBuilder::build_path(TreeElement &parent,
const char *elem_path = nullptr;
TreeElement *te_to_expand = &parent;
char name_buf[128], *name;
LISTBASE_FOREACH (PropertyElemRNA *, elem, &path_elems) {
if (!elem->next) {
@@ -339,8 +340,9 @@ void OverrideRNAPathTreeBuilder::build_path(TreeElement &parent,
if (RNA_property_type(elem->prop) == PROP_COLLECTION) {
const int coll_item_idx = RNA_property_collection_lookup_index(
&elem->ptr, elem->prop, &elem->next->ptr);
name = RNA_struct_name_get_alloc(&elem->next->ptr, name_buf, sizeof(name_buf), nullptr);
const char *coll_item_path = RNA_path_append(
previous_path, &elem->ptr, elem->prop, coll_item_idx, nullptr);
previous_path, &elem->ptr, elem->prop, coll_item_idx, name);
te_to_expand = &ensure_label_element_for_ptr(
*te_to_expand, coll_item_path, elem->next->ptr, index);
@@ -398,12 +400,14 @@ void OverrideRNAPathTreeBuilder::ensure_entire_collection(
TreeElement *previous_te = nullptr;
int item_idx = 0;
char name_buf[128], *name;
RNA_PROP_BEGIN (&override_data.override_rna_ptr, itemptr, &override_data.override_rna_prop) {
name = RNA_struct_name_get_alloc(&itemptr, name_buf, sizeof(name_buf), nullptr);
const char *coll_item_path = RNA_path_append(coll_prop_path,
&override_data.override_rna_ptr,
&override_data.override_rna_prop,
item_idx,
nullptr);
name);
IDOverrideLibraryPropertyOperation *item_operation =
BKE_lib_override_library_property_operation_find(&override_data.override_property,
nullptr,