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.
This commit is contained in:
parent
4647ffd918
commit
eb2a6f454b
Notes:
blender-bot
2023-02-14 08:10:06 +01:00
Referenced by issue #90318, Dragging a asset from the asset browser while the thumbnail is still loading results in a crash.
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue