diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 55b4d52ddf4..6382a555880 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1099,12 +1099,17 @@ static Py_ssize_t pyrna_prop_collection_length( BPy_PropertyRNA *self ) static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_ssize_t keynum) { PointerRNA newptr; + int len= RNA_property_collection_length(&self->ptr, self->prop); - if(keynum < 0) keynum += RNA_property_collection_length(&self->ptr, self->prop); - - if(RNA_property_collection_lookup_int(&self->ptr, self->prop, keynum, &newptr)) - return pyrna_struct_CreatePyObject(&newptr); + if(keynum < 0) keynum += len; + if(keynum >= 0 && keynum < len) { + if(RNA_property_collection_lookup_int(&self->ptr, self->prop, keynum, &newptr)) { + return pyrna_struct_CreatePyObject(&newptr); + } + PyErr_Format(PyExc_IndexError, "bpy_prop_collection[index]: index %d could not be found", keynum); + return NULL; + } PyErr_Format(PyExc_IndexError, "bpy_prop_collection[index]: index %d out of range", keynum); return NULL; } |