From 6845aad1a271db9861ba54e50c97146277eead4f Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Wed, 25 Aug 2021 13:09:44 +0200 Subject: 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 --- source/blender/makesrna/intern/rna_object.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source/blender/makesrna/intern/rna_object.c') 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; } -- cgit v1.2.3