Fix #104857: crash when datafiles/assets folder does not exist

This adds some simple null checks to avoid the crash. It might still
be good to improve the error message, but also does not seem as
important as avoiding the crash. Typically, users should not run into
this issue because the assets are shipped with Blender.
This commit is contained in:
Jacques Lucke
2023-02-27 14:02:03 +01:00
parent 9044ba0ae5
commit 79bce99260
2 changed files with 6 additions and 0 deletions
@@ -16,6 +16,9 @@ StringRefNull essentials_directory_path()
{
static std::string path = []() {
const char *datafiles_path = BKE_appdir_folder_id(BLENDER_DATAFILES, "assets");
if (datafiles_path == nullptr) {
return "";
}
return datafiles_path;
}();
return path;
@@ -63,6 +63,9 @@ AssetLibrary *AssetLibraryService::get_asset_library(
switch (type) {
case ASSET_LIBRARY_ESSENTIALS: {
const StringRefNull root_path = essentials_directory_path();
if (root_path.is_empty()) {
return nullptr;
}
AssetLibrary *library = get_asset_library_on_disk(root_path);
library->import_method_ = ASSET_IMPORT_APPEND_REUSE;