[Bf-blender-cvs] [a60e0f1dc17] asset-browser-poselib: Fix crash when applying pose from external repository in Asset Browser

Julian Eisel noreply at git.blender.org
Fri Mar 26 18:18:56 CET 2021


Commit: a60e0f1dc175fadf94a8e63f7120ebaa90761a37
Author: Julian Eisel
Date:   Fri Mar 26 18:16:52 2021 +0100
Branches: asset-browser-poselib
https://developer.blender.org/rBa60e0f1dc175fadf94a8e63f7120ebaa90761a37

Fix crash when applying pose from external repository in Asset Browser

The Asset Browser uses the `FileList` from the File Browser, which isn't
properly using the `AssetList` yet. So of course getting the file-path
from the asset list will fail.

For now just add a little hack to fall-back to get the data from the
Asset Browser directly.

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

M	source/blender/editors/armature/pose_lib_2.c
M	source/blender/editors/asset/asset_edit.cc
M	source/blender/editors/asset/asset_list.cc
M	source/blender/editors/include/ED_asset.h

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

diff --git a/source/blender/editors/armature/pose_lib_2.c b/source/blender/editors/armature/pose_lib_2.c
index da8a5bbd175..cc7927be764 100644
--- a/source/blender/editors/armature/pose_lib_2.c
+++ b/source/blender/editors/armature/pose_lib_2.c
@@ -403,7 +403,7 @@ static bAction *poselib_blend_init_get_action(bContext *C, wmOperator *op)
 
   pbd->temp_id_consumer = ED_asset_temp_id_consumer_create(&asset_handle);
   return (bAction *)ED_asset_temp_id_consumer_ensure_local_id(
-      pbd->temp_id_consumer, asset_library, ID_AC, CTX_data_main(C), op->reports);
+      pbd->temp_id_consumer, C, asset_library, ID_AC, CTX_data_main(C), op->reports);
 }
 
 /* Return true on success, false if the context isn't suitable. */
diff --git a/source/blender/editors/asset/asset_edit.cc b/source/blender/editors/asset/asset_edit.cc
index fb16344b37c..e4c6f94ed24 100644
--- a/source/blender/editors/asset/asset_edit.cc
+++ b/source/blender/editors/asset/asset_edit.cc
@@ -34,6 +34,8 @@
 #include "DNA_asset_types.h"
 #include "DNA_space_types.h"
 
+#include "ED_fileselect.h"
+
 #include "MEM_guardedalloc.h"
 
 #include "UI_interface_icons.h"
@@ -159,12 +161,13 @@ class AssetTemporaryIDConsumer : NonCopyable, NonMovable {
     return ED_assetlist_asset_local_id_get(&handle_);
   }
 
-  ID *import_id(const AssetLibraryReference &asset_library,
+  ID *import_id(const bContext *C,
+                const AssetLibraryReference &asset_library,
                 ID_Type id_type,
                 Main &bmain,
                 ReportList &reports)
   {
-    std::string asset_path = ED_assetlist_asset_filepath_get(asset_library, handle_);
+    std::string asset_path = ED_assetlist_asset_filepath_get(C, asset_library, handle_);
     if (asset_path.empty()) {
       return nullptr;
     }
@@ -202,6 +205,7 @@ void ED_asset_temp_id_consumer_free(AssetTempIDConsumer **consumer)
 }
 
 ID *ED_asset_temp_id_consumer_ensure_local_id(AssetTempIDConsumer *consumer_,
+                                              const bContext *C,
                                               const AssetLibraryReference *asset_library,
                                               ID_Type id_type,
                                               Main *bmain,
@@ -215,5 +219,5 @@ ID *ED_asset_temp_id_consumer_ensure_local_id(AssetTempIDConsumer *consumer_,
   if (ID *local_id = consumer->get_local_id()) {
     return local_id;
   }
-  return consumer->import_id(*asset_library, id_type, *bmain, *reports);
+  return consumer->import_id(C, *asset_library, id_type, *bmain, *reports);
 }
diff --git a/source/blender/editors/asset/asset_list.cc b/source/blender/editors/asset/asset_list.cc
index c418ef919e7..7c892f0b7dd 100644
--- a/source/blender/editors/asset/asset_list.cc
+++ b/source/blender/editors/asset/asset_list.cc
@@ -475,15 +475,36 @@ void ED_assetlist_iterate(const AssetLibraryReference *library_reference, AssetL
   }
 }
 
-std::string ED_assetlist_asset_filepath_get(const AssetLibraryReference &library_reference,
+/* TODO hack to use the File Browser path, so we can keep all the import logic handled by the asset
+ * API. Get rid of this once the File Browser is integrated better with the asset list. */
+static const char *assetlist_library_path_from_sfile_get_hack(const bContext *C)
+{
+  SpaceFile *sfile = CTX_wm_space_file(C);
+  if (!sfile || !ED_fileselect_is_asset_browser(sfile)) {
+    return nullptr;
+  }
+
+  FileAssetSelectParams *asset_select_params = ED_fileselect_get_asset_params(sfile);
+  if (!asset_select_params) {
+    return nullptr;
+  }
+
+  return filelist_dir(sfile->files);
+}
+
+std::string ED_assetlist_asset_filepath_get(const bContext *C,
+                                            const AssetLibraryReference &library_reference,
                                             const AssetHandle &asset_handle)
 {
   if (asset_handle.file_data->id || !asset_handle.file_data->asset_data) {
-    return nullptr;
+    return {};
   }
   const char *library_path = ED_assetlist_library_path(&library_reference);
   if (!library_path) {
-    return nullptr;
+    library_path = assetlist_library_path_from_sfile_get_hack(C);
+  }
+  if (!library_path) {
+    return {};
   }
   const char *asset_relpath = asset_handle.file_data->relpath;
 
diff --git a/source/blender/editors/include/ED_asset.h b/source/blender/editors/include/ED_asset.h
index 0fe07f72af5..d46846132dc 100644
--- a/source/blender/editors/include/ED_asset.h
+++ b/source/blender/editors/include/ED_asset.h
@@ -47,6 +47,7 @@ struct AssetLibraryReference ED_asset_library_reference_from_enum_value(int valu
 AssetTempIDConsumer *ED_asset_temp_id_consumer_create(const AssetHandle *handle);
 void ED_asset_temp_id_consumer_free(AssetTempIDConsumer **consumer);
 struct ID *ED_asset_temp_id_consumer_ensure_local_id(AssetTempIDConsumer *consumer,
+                                                     const struct bContext *C,
                                                      const AssetLibraryReference *asset_library,
                                                      ID_Type id_type,
                                                      struct Main *bmain,
@@ -76,7 +77,8 @@ void ED_operatortypes_asset(void);
 
 /* TODO move to C++ asset-list header? */
 #ifdef __cplusplus
-std::string ED_assetlist_asset_filepath_get(const AssetLibraryReference &library_reference,
+std::string ED_assetlist_asset_filepath_get(const bContext *C,
+                                            const AssetLibraryReference &library_reference,
                                             const AssetHandle &asset_handle);
 
 #  include "BLI_function_ref.hh"



More information about the Bf-blender-cvs mailing list