[Bf-blender-cvs] [8f4e3458ac0] tracking_tools: Tracking tools: Fix crash in tool header

Sergey Sharybin noreply at git.blender.org
Thu May 12 13:05:14 CEST 2022


Commit: 8f4e3458ac020f593ee9c8bf67d2c27d1ba10932
Author: Sergey Sharybin
Date:   Thu May 12 12:55:55 2022 +0200
Branches: tracking_tools
https://developer.blender.org/rB8f4e3458ac020f593ee9c8bf67d2c27d1ba10932

Tracking tools: Fix crash in tool header

The draw function should not modify the region visibility as it will
cause memory free in the middle of drawing. More proper way of hiding
the tool header is to do it in C.

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

M	release/scripts/startup/bl_ui/space_clip.py
M	source/blender/blenloader/intern/versioning_300.c
M	source/blender/editors/space_clip/space_clip.c

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

diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py
index de06ff27340..f909d73d4c6 100644
--- a/release/scripts/startup/bl_ui/space_clip.py
+++ b/release/scripts/startup/bl_ui/space_clip.py
@@ -137,9 +137,6 @@ class CLIP_HT_tool_header(Header):
 
             self.draw_mode_settings(context)
 
-        else:
-            sc.show_region_tool_header = False
-
     def draw_tool_settings(self, context):
         layout = self.layout
         # Active Tool
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 17585c315d7..23d83684329 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -2569,24 +2569,6 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
         }
       }
     }
-
-    {
-      for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
-        LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
-          LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
-            ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase :
-                                                                   &sl->regionbase;
-            if ((sl->spacetype == SPACE_CLIP) &&
-                (do_versions_find_region_or_null(regionbase, RGN_TYPE_TOOL_HEADER) == NULL)) {
-              ARegion *region = do_versions_add_region_if_not_found(
-                  regionbase, RGN_TYPE_TOOL_HEADER, "tool header", RGN_TYPE_HEADER);
-              region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM :
-                                                                    RGN_ALIGN_TOP;
-            }
-          }
-        }
-      }
-    }
   }
 
   if (!MAIN_VERSION_ATLEAST(bmain, 302, 9)) {
@@ -3063,5 +3045,28 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
         }
       }
     }
+
+    {
+      for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) {
+        LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+          LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+            ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase :
+                                                                   &sl->regionbase;
+            if ((sl->spacetype == SPACE_CLIP) &&
+                (do_versions_find_region_or_null(regionbase, RGN_TYPE_TOOL_HEADER) == NULL)) {
+              SpaceClip *space_clip = (SpaceClip *)sl;
+              ARegion *region = do_versions_add_region_if_not_found(
+                  regionbase, RGN_TYPE_TOOL_HEADER, "tool header", RGN_TYPE_HEADER);
+              region->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM :
+                                                                    RGN_ALIGN_TOP;
+
+              if (space_clip->view != SC_VIEW_CLIP) {
+                region->flag |= RGN_FLAG_HIDDEN;
+              }
+            }
+          }
+        }
+      }
+    }
   }
 }
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index 7837320309e..f4b88e1caed 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -675,10 +675,12 @@ static void clip_refresh(const bContext *C, ScrArea *area)
   SpaceClip *sc = (SpaceClip *)area->spacedata.first;
   ARegion *region_main = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
   ARegion *region_tools = BKE_area_find_region_type(area, RGN_TYPE_TOOLS);
+  ARegion *region_tool_header = BKE_area_find_region_type(area, RGN_TYPE_TOOL_HEADER);
   ARegion *region_preview = ED_clip_has_preview_region(C, area);
   ARegion *region_properties = ED_clip_has_properties_region(area);
   ARegion *region_channels = ED_clip_has_channels_region(area);
-  bool main_visible = false, preview_visible = false, tools_visible = false;
+  bool main_visible = false, preview_visible = false, tools_visible = false,
+       tool_header_visible = false;
   bool properties_visible = false, channels_visible = false;
   bool view_changed = false;
 
@@ -687,6 +689,7 @@ static void clip_refresh(const bContext *C, ScrArea *area)
       main_visible = true;
       preview_visible = false;
       tools_visible = true;
+      tool_header_visible = true;
       properties_visible = true;
       channels_visible = false;
       break;
@@ -694,6 +697,7 @@ static void clip_refresh(const bContext *C, ScrArea *area)
       main_visible = false;
       preview_visible = true;
       tools_visible = false;
+      tool_header_visible = false;
       properties_visible = false;
       channels_visible = false;
 
@@ -703,6 +707,7 @@ static void clip_refresh(const bContext *C, ScrArea *area)
       main_visible = false;
       preview_visible = true;
       tools_visible = false;
+      tool_header_visible = false;
       properties_visible = false;
       channels_visible = true;
 
@@ -710,10 +715,18 @@ static void clip_refresh(const bContext *C, ScrArea *area)
       break;
   }
 
+  /* TODO(sergey): Look into preserving the alignment of the regions when hiding, so that we do
+   * not need to have all the logic about alignment here. */
   view_changed |= clip_set_region_visible(C, region_main, main_visible, RGN_ALIGN_NONE, false);
   view_changed |= clip_set_region_visible(
       C, region_properties, properties_visible, RGN_ALIGN_RIGHT, false);
   view_changed |= clip_set_region_visible(C, region_tools, tools_visible, RGN_ALIGN_LEFT, false);
+  view_changed |= clip_set_region_visible(C,
+                                          region_tool_header,
+                                          tool_header_visible,
+                                          (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM :
+                                                                            RGN_ALIGN_TOP,
+                                          false);
   view_changed |= clip_set_region_visible(
       C, region_preview, preview_visible, RGN_ALIGN_NONE, true);
   view_changed |= clip_set_region_visible(



More information about the Bf-blender-cvs mailing list