Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-12-15 18:58:30 +0300
committerJulian Eisel <julian@blender.org>2020-12-15 19:03:49 +0300
commit990406e1ff9371a8c896b71171caa876cfdff2f6 (patch)
treedc726d606be0df6c549bb63a09484e473b3dd2d9 /source/blender/makesrna/intern/rna_space.c
parent7dc8db7cd135e7b26fccc1cc6728cac8b510de70 (diff)
Fix crash when deleting/renaming asset library while it's visible
Storing the asset library reference by name wasn't a good idea, I thought it would work with a careful fallback, but it's easier to just use the index instead. So change to using indices, make sure fallback methods work reliable and make sure the file list is updated when asset libraries are removed. I added a new notifier type for the latter, I prefer not using file notifiers in asset-library/preferences code. We have more than enough values for notifiers left.
Diffstat (limited to 'source/blender/makesrna/intern/rna_space.c')
-rw-r--r--source/blender/makesrna/intern/rna_space.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 59012ce4528..0e779c8cc97 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2482,11 +2482,10 @@ static int rna_FileAssetSelectParams_asset_library_get(PointerRNA *ptr)
/* Note that the path isn't checked for validity here. If an invalid library path is used, the
* Asset Browser can give a nice hint on what's wrong. */
- const bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_name(
- &U, params->asset_library.custom_library_identifier);
- const int index = BKE_preferences_asset_library_get_index(&U, user_library);
- if (index > -1) {
- return FILE_ASSET_LIBRARY_CUSTOM + index;
+ const bUserAssetLibrary *user_library = BKE_preferences_asset_library_find_from_index(
+ &U, params->asset_library.custom_library_index);
+ if (user_library) {
+ return FILE_ASSET_LIBRARY_CUSTOM + params->asset_library.custom_library_index;
}
BLI_assert(0);
@@ -2500,7 +2499,7 @@ static void rna_FileAssetSelectParams_asset_library_set(PointerRNA *ptr, int val
/* Simple case: Predefined repo, just set the value. */
if (value < FILE_ASSET_LIBRARY_CUSTOM) {
params->asset_library.type = value;
- params->asset_library.custom_library_identifier[0] = '\0';
+ params->asset_library.custom_library_index = -1;
BLI_assert(ELEM(value, FILE_ASSET_LIBRARY_LOCAL));
return;
}
@@ -2511,10 +2510,12 @@ static void rna_FileAssetSelectParams_asset_library_set(PointerRNA *ptr, int val
/* Note that the path isn't checked for validity here. If an invalid library path is used, the
* Asset Browser can give a nice hint on what's wrong. */
const bool is_valid = (user_library->name[0] && user_library->path[0]);
- if (user_library && is_valid) {
- BLI_strncpy(params->asset_library.custom_library_identifier,
- user_library->name,
- sizeof(params->asset_library.custom_library_identifier));
+ if (!user_library) {
+ params->asset_library.type = FILE_ASSET_LIBRARY_LOCAL;
+ params->asset_library.custom_library_index = -1;
+ }
+ else if (user_library && is_valid) {
+ params->asset_library.custom_library_index = value - FILE_ASSET_LIBRARY_CUSTOM;
params->asset_library.type = FILE_ASSET_LIBRARY_CUSTOM;
}
}