diff options
author | Philipp Oeser <info@graphics-engineer.com> | 2021-08-25 14:09:44 +0300 |
---|---|---|
committer | Philipp Oeser <info@graphics-engineer.com> | 2021-08-27 12:02:58 +0300 |
commit | 6845aad1a271db9861ba54e50c97146277eead4f (patch) | |
tree | 4ded81a1b6d5fe9d2e02332f6df6bf1622dcc889 /source/blender/makesrna | |
parent | 7dba879829469de6179302147d19cf17fb9fa94b (diff) |
Fix T90907: RNA pointers for material slots are not unique across IDs
Caused by {rB1a81d268a19f}.
This caused e.g. ALT-clicking the 'Link' button to not propagate to
other selected objects (same as the 'Copy To Selected' context menu
entry).
If these are not unique across IDs, checks in ui_selectcontext_begin()
or copy_to_selected_button() could fail.
Now offset by ID pointer.
thx @JacquesLucke for clarification on the POINTER_* macros (and why
not to use them)!
Maniphest Tasks: T90907
Differential Revision: https://developer.blender.org/D12321
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 0f6b89722a4..d3cd3158db1 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -1326,8 +1326,8 @@ static int rna_Object_rotation_4d_editable(PointerRNA *ptr, int index) static int rna_MaterialSlot_index(PointerRNA *ptr) { - /* There is an offset of one, so that `ptr->data` is not null. */ - return POINTER_AS_INT(ptr->data) - 1; + /* There is an offset, so that `ptr->data` is not null and unique across IDs. */ + return (uintptr_t)ptr->data - (uintptr_t)ptr->owner_id; } static int rna_MaterialSlot_material_editable(PointerRNA *ptr, const char **UNUSED(r_info)) @@ -1490,10 +1490,11 @@ static void rna_Object_material_slots_next(CollectionPropertyIterator *iter) static PointerRNA rna_Object_material_slots_get(CollectionPropertyIterator *iter) { PointerRNA ptr; - RNA_pointer_create((ID *)iter->internal.count.ptr, + ID *id = (ID *)iter->internal.count.ptr; + RNA_pointer_create(id, &RNA_MaterialSlot, - /* Add one, so that `ptr->data` is not null. */ - POINTER_FROM_INT(iter->internal.count.item + 1), + /* Add offset, so that `ptr->data` is not null and unique across IDs. */ + (void *)(iter->internal.count.item + (uintptr_t)id), &ptr); return ptr; } |