[Bf-blender-cvs] [eb2a6f454bd] master: Fix T90318: Dragging asset while Asset Browser is still loading crashes

Julian Eisel noreply at git.blender.org
Fri Jul 30 16:01:34 CEST 2021


Commit: eb2a6f454bd07442d16001e25dcf407d4e8f7533
Author: Julian Eisel
Date:   Fri Jul 30 15:54:54 2021 +0200
Branches: master
https://developer.blender.org/rBeb2a6f454bd07442d16001e25dcf407d4e8f7533

Fix T90318: Dragging asset while Asset Browser is still loading crashes

This partially reverts cb0b017d8f51: We can't store the asset handle in
the drag data, because the file pointer it wraps may be freed as the
Asset Browser generates its file list.

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

M	source/blender/editors/interface/interface.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_dragdrop.c

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

diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 959716a5247..a2b25aed582 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -57,6 +57,8 @@
 #include "BKE_screen.h"
 #include "BKE_unit.h"
 
+#include "ED_asset.h"
+
 #include "GPU_matrix.h"
 #include "GPU_state.h"
 
@@ -6189,10 +6191,9 @@ void UI_but_drag_set_asset(uiBut *but,
 {
   wmDragAsset *asset_drag = MEM_mallocN(sizeof(*asset_drag), "wmDragAsset");
 
-  asset_drag->asset_handle = MEM_mallocN(sizeof(asset_drag->asset_handle),
-                                         "wmDragAsset asset handle");
-  *asset_drag->asset_handle = *asset;
+  BLI_strncpy(asset_drag->name, ED_asset_handle_get_name(asset), sizeof(asset_drag->name));
   asset_drag->path = path;
+  asset_drag->id_type = ED_asset_handle_get_id_type(asset);
   asset_drag->import_type = import_type;
 
   but->dragtype = WM_DRAG_ASSET;
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 5baa12f7367..54f10e259f9 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -53,7 +53,6 @@
 #include "BKE_screen.h"
 #include "BKE_workspace.h"
 
-#include "ED_asset.h"
 #include "ED_render.h"
 #include "ED_screen.h"
 #include "ED_space_api.h"
@@ -496,7 +495,7 @@ static ID_Type view3d_drop_id_in_main_region_poll_get_id_type(bContext *C,
 
   wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
   if (asset_drag) {
-    return ED_asset_handle_get_id_type(asset_drag->asset_handle);
+    return asset_drag->id_type;
   }
 
   return 0;
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index cc8fb307c92..4ead0b2699c 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -924,10 +924,13 @@ typedef struct wmDragID {
 } wmDragID;
 
 typedef struct wmDragAsset {
-  /* Owning pointer. Contains the file with all the asset data (name, local ID, etc.) */
-  struct AssetHandle *asset_handle;
+  /* Note: Can't store the AssetHandle here, since the FileDirEntry it wraps may be freed while
+   * dragging. So store necessary data here directly. */
+
+  char name[64]; /* MAX_NAME */
   /* Always freed. */
   const char *path;
+  int id_type;
   int import_type; /* eFileAssetImportType */
 } wmDragAsset;
 
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index 319e83f667f..db72dd2a819 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -42,8 +42,6 @@
 #include "BKE_idtype.h"
 #include "BKE_lib_id.h"
 
-#include "ED_asset.h"
-
 #include "GPU_shader.h"
 #include "GPU_state.h"
 #include "GPU_viewport.h"
@@ -198,7 +196,6 @@ void WM_drag_data_free(int dragtype, void *poin)
   /* Not too nice, could become a callback. */
   if (dragtype == WM_DRAG_ASSET) {
     wmDragAsset *asset_drag = poin;
-    MEM_SAFE_FREE(asset_drag->asset_handle);
     MEM_freeN((void *)asset_drag->path);
   }
   MEM_freeN(poin);
@@ -376,14 +373,13 @@ wmDragAsset *WM_drag_get_asset_data(const wmDrag *drag, int idcode)
   }
 
   wmDragAsset *asset_drag = drag->poin;
-  ID_Type idtype = ED_asset_handle_get_id_type(asset_drag->asset_handle);
-  return (ELEM(idcode, 0, (int)idtype)) ? asset_drag : NULL;
+  return (ELEM(idcode, 0, asset_drag->id_type)) ? asset_drag : NULL;
 }
 
 static ID *wm_drag_asset_id_import(wmDragAsset *asset_drag)
 {
-  const char *name = ED_asset_handle_get_name(asset_drag->asset_handle);
-  ID_Type idtype = ED_asset_handle_get_id_type(asset_drag->asset_handle);
+  const char *name = asset_drag->name;
+  ID_Type idtype = asset_drag->id_type;
 
   switch ((eFileAssetImportType)asset_drag->import_type) {
     case FILE_ASSET_IMPORT_LINK:
@@ -449,8 +445,7 @@ void WM_drag_free_imported_drag_ID(struct Main *bmain, wmDrag *drag, wmDropBox *
     return;
   }
 
-  ID_Type idtype = ED_asset_handle_get_id_type(asset_drag->asset_handle);
-  ID *id = BKE_libblock_find_name(bmain, idtype, name);
+  ID *id = BKE_libblock_find_name(bmain, asset_drag->id_type, name);
   if (id) {
     BKE_id_delete(bmain, id);
   }
@@ -484,7 +479,7 @@ static const char *wm_drag_name(wmDrag *drag)
     }
     case WM_DRAG_ASSET: {
       const wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
-      return ED_asset_handle_get_name(asset_drag->asset_handle);
+      return asset_drag->name;
     }
     case WM_DRAG_PATH:
     case WM_DRAG_NAME:



More information about the Bf-blender-cvs mailing list