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.
This commit is contained in:
Julian Eisel 2022-02-09 18:53:39 +01:00
parent 86ea1ad5df
commit 9530fb60ad
2 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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();
}
/**