[Bf-blender-cvs] [3f3b4745b6a] master: Fix T87187: Area.type & ui_type empty area access fails

Campbell Barton noreply at git.blender.org
Tue Apr 6 05:13:45 CEST 2021


Commit: 3f3b4745b6ad99a0503fba4793d0f1febedadebc
Author: Campbell Barton
Date:   Tue Apr 6 13:08:35 2021 +1000
Branches: master
https://developer.blender.org/rB3f3b4745b6ad99a0503fba4793d0f1febedadebc

Fix T87187: Area.type & ui_type empty area access fails

Reading Area.type & ui_type printed an error from `pyrna_enum_to_py`
and returned an empty string.

As empty is a valid value, include it in the property enum list.

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

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

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

diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c
index 6cf1d7a923b..fba1d3cda9a 100644
--- a/source/blender/makesrna/intern/rna_screen.c
+++ b/source/blender/makesrna/intern/rna_screen.c
@@ -112,18 +112,6 @@ static bool rna_Screen_fullscreen_get(PointerRNA *ptr)
   return (screen->state == SCREENMAXIMIZED);
 }
 
-/* UI compatible list: should not be needed, but for now we need to keep EMPTY
- * at least in the static version of this enum for python scripts. */
-static const EnumPropertyItem *rna_Area_type_itemf(bContext *UNUSED(C),
-                                                   PointerRNA *UNUSED(ptr),
-                                                   PropertyRNA *UNUSED(prop),
-                                                   bool *r_free)
-{
-  /* +1 to skip SPACE_EMPTY */
-  *r_free = false;
-  return rna_enum_space_type_items + 1;
-}
-
 static int rna_Area_type_get(PointerRNA *ptr)
 {
   ScrArea *area = (ScrArea *)ptr->data;
@@ -142,6 +130,11 @@ static void rna_Area_type_set(PointerRNA *ptr, int value)
   }
 
   ScrArea *area = (ScrArea *)ptr->data;
+  /* Empty areas are locked. */
+  if ((value == SPACE_EMPTY) || (area->spacetype == SPACE_EMPTY)) {
+    return;
+  }
+
   area->butspacetype = value;
 }
 
@@ -188,16 +181,20 @@ static void rna_Area_type_update(bContext *C, PointerRNA *ptr)
 }
 
 static const EnumPropertyItem *rna_Area_ui_type_itemf(bContext *C,
-                                                      PointerRNA *UNUSED(ptr),
+                                                      PointerRNA *ptr,
                                                       PropertyRNA *UNUSED(prop),
                                                       bool *r_free)
 {
   EnumPropertyItem *item = NULL;
   int totitem = 0;
 
-  /* +1 to skip SPACE_EMPTY */
-  for (const EnumPropertyItem *item_from = rna_enum_space_type_items + 1; item_from->identifier;
-       item_from++) {
+  ScrArea *area = (ScrArea *)ptr->data;
+  const EnumPropertyItem *item_from = rna_enum_space_type_items;
+  if (area->spacetype != SPACE_EMPTY) {
+    item_from += 1; /* +1 to skip SPACE_EMPTY */
+  }
+
+  for (; item_from->identifier; item_from++) {
     if (ELEM(item_from->value, SPACE_TOPBAR, SPACE_STATUSBAR)) {
       continue;
     }
@@ -224,6 +221,10 @@ static const EnumPropertyItem *rna_Area_ui_type_itemf(bContext *C,
 static int rna_Area_ui_type_get(PointerRNA *ptr)
 {
   ScrArea *area = ptr->data;
+  /* This is for the Python API which may inspect empty areas. */
+  if (UNLIKELY(area->spacetype == SPACE_EMPTY)) {
+    return SPACE_EMPTY;
+  }
   const int area_type = rna_Area_type_get(ptr);
   const bool area_changing = area->butspacetype != SPACE_EMPTY;
   int value = area_type << 16;
@@ -252,6 +253,10 @@ static void rna_Area_ui_type_set(PointerRNA *ptr, int value)
 {
   ScrArea *area = ptr->data;
   const int space_type = value >> 16;
+  /* Empty areas are locked. */
+  if ((space_type == SPACE_EMPTY) || (area->spacetype == SPACE_EMPTY)) {
+    return;
+  }
   SpaceType *st = BKE_spacetype_from_id(space_type);
 
   rna_Area_type_set(ptr, space_type);
@@ -380,12 +385,17 @@ static void rna_def_area(BlenderRNA *brna)
   RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", HEADER_NO_PULLDOWN);
   RNA_def_property_ui_text(prop, "Show Menus", "Show menus in the header");
 
+  /* Note on space type use of #SPACE_EMPTY, this is not visible to the user,
+   * and script authors should be able to assign this value, however the value may be set
+   * and needs to be read back by script authors.
+   *
+   * This happens when an area is full-screen (when #ScrArea.full is set).
+   * in this case reading the empty value is needed, but it should never be set, see: T87187. */
   prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_sdna(prop, NULL, "spacetype");
   RNA_def_property_enum_items(prop, rna_enum_space_type_items);
   RNA_def_property_enum_default(prop, SPACE_VIEW3D);
-  RNA_def_property_enum_funcs(
-      prop, "rna_Area_type_get", "rna_Area_type_set", "rna_Area_type_itemf");
+  RNA_def_property_enum_funcs(prop, "rna_Area_type_get", "rna_Area_type_set", NULL);
   RNA_def_property_ui_text(prop, "Editor Type", "Current editor type for this area");
   RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);



More information about the Bf-blender-cvs mailing list