Fix: segfault when indexing into some collections with strings.
This happens when the collection's item type doesn't have a 'nameproperty' to index with. For debug builds we error out with an assert, since in general this shouldn't happen. For release builds Python will report item not found. Pull Request: https://projects.blender.org/blender/blender/pulls/107086
This commit is contained in:
parent
d818d05415
commit
5bb3a3f157
|
@ -2371,6 +2371,13 @@ static PyObject *pyrna_prop_collection_subscript_str(BPy_PropertyRNA *self, cons
|
|||
RNA_property_collection_begin(&self->ptr, self->prop, &iter);
|
||||
for (int i = 0; iter.valid; RNA_property_collection_next(&iter), i++) {
|
||||
PropertyRNA *nameprop = RNA_struct_name_property(iter.ptr.type);
|
||||
BLI_assert_msg(
|
||||
nameprop,
|
||||
"Attempted to use a string to index into a collection of items with no 'nameproperty'.");
|
||||
if (nameprop == NULL) {
|
||||
// For non-debug builds, bail if there's no 'nameproperty' to check.
|
||||
break;
|
||||
}
|
||||
char *nameptr = RNA_property_string_get_alloc(
|
||||
&iter.ptr, nameprop, name, sizeof(name), &namelen);
|
||||
if ((keylen == namelen) && STREQ(nameptr, keyname)) {
|
||||
|
|
Loading…
Reference in New Issue