[Bf-blender-cvs] [9530fb60adf] asset-browser-grid-view: Fix crash when loading files with asset browser open

Julian Eisel noreply at git.blender.org
Wed Feb 9 19:01:19 CET 2022


Commit: 9530fb60adf664b7be3c766e042a5f73e5443e59
Author: Julian Eisel
Date:   Wed Feb 9 18:53:39 2022 +0100
Branches: asset-browser-grid-view
https://developer.blender.org/rB9530fb60adf664b7be3c766e042a5f73e5443e59

Fix crash when loading files with asset browser open

Some fun with static memory. When loading a file, the asset-library
service was destructed since some while ago. For the old asset browser
that wasn't a problem, since its storage was recreated from scratch. But
the new asset browser accesses the global asset library storage of the
asset system which is static and thus stays alive if a different file is
loaded.

For now just destruct the global asset library storage when loading
a new file.

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

M	source/blender/editors/asset/intern/asset_list.cc
M	source/blender/windowmanager/intern/wm_files.c

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

diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc
index 1381bfbb78b..387ad778241 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -363,6 +363,7 @@ class AssetListStorage {
       const AssetLibraryReference &library_reference, eFileSelectType filesel_type);
 
   static AssetListMap &global_storage();
+  static bool &global_storage_is_destructed();
 };
 
 void AssetListStorage::fetch_library(const AssetLibraryReference &library_reference,
@@ -383,6 +384,7 @@ void AssetListStorage::fetch_library(const AssetLibraryReference &library_refere
 void AssetListStorage::destruct()
 {
   global_storage().~AssetListMap();
+  global_storage_is_destructed() = true;
 }
 
 AssetList *AssetListStorage::lookup_list(const AssetLibraryReference &library_ref)
@@ -435,9 +437,19 @@ std::tuple<AssetList &, AssetListStorage::is_new_t> AssetListStorage::ensure_lis
 AssetListStorage::AssetListMap &AssetListStorage::global_storage()
 {
   static AssetListMap global_storage_;
+  if (global_storage_is_destructed()) {
+    global_storage_ = AssetListMap();
+    global_storage_is_destructed() = false;
+  }
   return global_storage_;
 }
 
+bool &AssetListStorage::global_storage_is_destructed()
+{
+  static bool is_destructed = false;
+  return is_destructed;
+}
+
 /** \} */
 
 }  // namespace blender::ed::asset
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 9b9aa37a251..d9f55949728 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -621,6 +621,10 @@ static void wm_file_read_pre(bContext *C, bool use_data, bool UNUSED(use_userdef
   UI_view2d_zoom_cache_reset();
 
   ED_preview_restart_queue_free();
+  /* #AssetLibraryService and the contained #AssetLibrary instances are destroyed on file loading.
+   * Asset lists may still reference them, so clear the asset list storage entirely for now. Later
+   * on, asset lists should actually live in the library, so this can be solved differently. */
+  ED_assetlist_storage_exit();
 }
 
 /**



More information about the Bf-blender-cvs mailing list