[Bf-blender-cvs] [37fb69e0203] master: Fix (unreported) `RNA_property_editable_index`.

Bastien Montagne noreply at git.blender.org
Tue Feb 22 15:38:11 CET 2022


Commit: 37fb69e02033b59895173aa2f47858ff3923afad
Author: Bastien Montagne
Date:   Tue Feb 22 15:33:52 2022 +0100
Branches: master
https://developer.blender.org/rB37fb69e02033b59895173aa2f47858ff3923afad

Fix (unreported) `RNA_property_editable_index`.

NOTE: This function is currently unused. However, it does use a callback
defined by a few RNA properties through
`RNA_def_property_editable_array_func`, so don't think it should be
removed without further thinking.

This function had two main issues:
* It was doing bitwise AND on potentially three sources of property
  flag, when actually used `RNA_property_editable` just use one source
  ever.
* It was completely ignoring liboverride cases.

TODO: Deduplicate code between `RNA_property_editable`,
`RNA_property_editable_info` and `RNA_property_editable_index`.

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

M	source/blender/makesrna/intern/rna_access.c

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

diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 5a43fc2b053..59acbc81afd 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1980,29 +1980,40 @@ bool RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop)
   return (flag & PROP_EDITABLE) != 0;
 }
 
-bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index)
+bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop_orig, int index)
 {
-  ID *id;
-  int flag;
-
   BLI_assert(index >= 0);
 
-  prop = rna_ensure_property(prop);
+  ID *id = ptr->owner_id;
+  const char *dummy_info;
+
+  PropertyRNA *prop = rna_ensure_property(prop_orig);
 
-  flag = prop->flag;
+  const int flag = prop->itemeditable != NULL ?
+                       prop->itemeditable(ptr, index) :
+                       (prop->editable != NULL ? prop->editable(ptr, &dummy_info) : prop->flag);
 
-  if (prop->editable) {
-    const char *dummy_info;
-    flag &= prop->editable(ptr, &dummy_info);
+  /* Early return if the property itself is not editable. */
+  if ((flag & PROP_EDITABLE) == 0 || (flag & PROP_REGISTER) != 0) {
+    return false;
   }
 
-  if (prop->itemeditable) {
-    flag &= prop->itemeditable(ptr, index);
+  /* If there is no owning ID, the property is editable at this point. */
+  if (id == NULL) {
+    return true;
   }
 
-  id = ptr->owner_id;
+  /* Handle linked or liboverride ID cases. */
+  const bool is_linked_prop_exception = (prop->flag & PROP_LIB_EXCEPTION) != 0;
+  if (ID_IS_LINKED(id)) {
+    return is_linked_prop_exception;
+  }
+  if (ID_IS_OVERRIDE_LIBRARY(id)) {
+    return RNA_property_overridable_get(ptr, prop_orig);
+  }
 
-  return (flag & PROP_EDITABLE) && (!id || !ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION));
+  /* At this point, property is owned by a local ID and therefore fully editable. */
+  return true;
 }
 
 bool RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop)



More information about the Bf-blender-cvs mailing list