[Bf-blender-cvs] [138b3815e52] master: Fix (unreported) missing clear of deprecated Window data on fileread.

Bastien Montagne noreply at git.blender.org
Fri Jan 27 15:15:00 CET 2023


Commit: 138b3815e528b062844c5fa8ef0e2f00b1b21274
Author: Bastien Montagne
Date:   Fri Jan 27 15:01:29 2023 +0100
Branches: master
https://developer.blender.org/rB138b3815e528b062844c5fa8ef0e2f00b1b21274

Fix (unreported) missing clear of deprecated Window data on fileread.

rB7f564d74f9ed (6 years ago!) forgot to clear the deprecated
`Window->screen` pointer on file read for recent-enough .blend files.

This is required since a valid value is always written in .blend files
for that pointer, to ensure backward compatibility.

The issue was never detected so far because that pointer is explicitely
reset to NULL after filewrite, which includes any memfile undostep
write, and usually existing UI data is re-used instead of loading the
one from the .blend file, so thedden  assert in `blo_lib_link_restore`
would never be triggered.

Now moved the assert at the end of `setup_app_data` to ensure it always
get checked.

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

M	source/blender/blenkernel/intern/blendfile.cc
M	source/blender/blenloader/intern/readfile.cc
M	source/blender/blenloader/intern/versioning_280.c

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

diff --git a/source/blender/blenkernel/intern/blendfile.cc b/source/blender/blenkernel/intern/blendfile.cc
index 68f37df9ca9..b7294156cb2 100644
--- a/source/blender/blenkernel/intern/blendfile.cc
+++ b/source/blender/blenkernel/intern/blendfile.cc
@@ -438,6 +438,16 @@ static void setup_app_data(bContext *C,
     /* We need to rebuild some of the deleted override rules (for UI feedback purpose). */
     BKE_lib_override_library_main_operations_create(bmain, true, nullptr);
   }
+
+  /* Sanity checks. */
+#ifndef NDEBUG
+  LISTBASE_FOREACH (wmWindowManager *, wm, &bmain->wm) {
+    LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
+      /* This pointer is deprecated and should always be nullptr. */
+      BLI_assert(win->screen == nullptr);
+    }
+  }
+#endif
 }
 
 static void setup_app_blend_file_data(bContext *C,
diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc
index 2ffe8386166..e2721820f96 100644
--- a/source/blender/blenloader/intern/readfile.cc
+++ b/source/blender/blenloader/intern/readfile.cc
@@ -2701,8 +2701,6 @@ void blo_lib_link_restore(Main *oldmain,
      * all workspaces), that one only focuses one current active screen, takes care of
      * potential local view, and needs window's scene pointer to be final... */
     lib_link_window_scene_data_restore(win, win->scene, cur_view_layer);
-
-    BLI_assert(win->screen == nullptr);
   }
 
   lib_link_wm_xr_data_restore(id_map, &curwm->xr);
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 980c8894e10..2e9a16bc945 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1297,7 +1297,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports))
     }
   }
 
-  /* New workspace design */
+  /* New workspace design. */
   if (!MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
     do_version_workspaces_after_lib_link(bmain);
   }
@@ -1970,6 +1970,16 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
   }
 #endif
 
+  /* Files from this version included do get a valid `win->screen` pointer written for backward
+   * compatibility, however this should never be used nor needed, so clear these pointers here. */
+  if (MAIN_VERSION_ATLEAST(bmain, 280, 1)) {
+    for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
+      LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
+        win->screen = NULL;
+      }
+    }
+  }
+
   if (!MAIN_VERSION_ATLEAST(bmain, 280, 3)) {
     /* init grease pencil grids and paper */
     if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "gpencil_paper_color[3]")) {



More information about the Bf-blender-cvs mailing list