[Bf-blender-cvs] [6845aad1a27] master: Fix T90907: RNA pointers for material slots are not unique across IDs

Philipp Oeser noreply at git.blender.org
Fri Aug 27 11:07:00 CEST 2021


Commit: 6845aad1a271db9861ba54e50c97146277eead4f
Author: Philipp Oeser
Date:   Wed Aug 25 13:09:44 2021 +0200
Branches: master
https://developer.blender.org/rB6845aad1a271db9861ba54e50c97146277eead4f

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

===================================================================

M	source/blender/editors/space_buttons/buttons_context.c
M	source/blender/makesrna/intern/rna_object.c

===================================================================

diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c
index 70b715e0119..bf855db07e9 100644
--- a/source/blender/editors/space_buttons/buttons_context.c
+++ b/source/blender/editors/space_buttons/buttons_context.c
@@ -987,7 +987,8 @@ int /*eContextResult*/ buttons_context(const bContext *C,
           matnr = 0;
         }
         /* Keep aligned with rna_Object_material_slots_get. */
-        CTX_data_pointer_set(result, &ob->id, &RNA_MaterialSlot, POINTER_FROM_INT(matnr + 1));
+        CTX_data_pointer_set(
+            result, &ob->id, &RNA_MaterialSlot, (void *)(matnr + (uintptr_t)&ob->id));
       }
     }
 
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;
 }



More information about the Bf-blender-cvs mailing list