Fix crash when loading asset library takes multiple redraws
This commit is contained in:
parent
2ce7f02a06
commit
fdc5301205
|
@ -80,8 +80,8 @@ class AssetList : NonCopyable {
|
|||
FileListWrapper filelist_;
|
||||
/** Storage for asset handles, items are lazy-created on request.
|
||||
* Asset handles are stored as a pointer here, to ensure a consistent memory address (address
|
||||
* inside the map changes as the map changes). */
|
||||
mutable Map<const FileDirEntry *, std::unique_ptr<AssetHandle>> asset_handle_map_;
|
||||
* inside the map changes as the map changes). */
|
||||
mutable Map<uint32_t, std::unique_ptr<AssetHandle>> asset_handle_map_;
|
||||
AssetLibraryReference library_ref_;
|
||||
|
||||
public:
|
||||
|
@ -186,8 +186,11 @@ bool AssetList::needsRefetch() const
|
|||
|
||||
AssetHandle &AssetList::asset_handle_from_file(const FileDirEntry &file) const
|
||||
{
|
||||
return *asset_handle_map_.lookup_or_add(&file,
|
||||
std::make_unique<AssetHandle>(AssetHandle{&file}));
|
||||
AssetHandle &asset = *asset_handle_map_.lookup_or_add(
|
||||
file.uid, std::make_unique<AssetHandle>(AssetHandle{&file}));
|
||||
/* The file is recreated while loading, update the pointer here. */
|
||||
asset.file_data = &file;
|
||||
return asset;
|
||||
}
|
||||
|
||||
void AssetList::iterate(AssetListIterFn fn) const
|
||||
|
|
|
@ -76,20 +76,14 @@ AssetGridViewItem::AssetGridViewItem(const AssetLibraryReference &asset_library_
|
|||
AssetHandle &asset)
|
||||
: ui::PreviewGridItem(ED_asset_handle_get_name(&asset),
|
||||
ED_assetlist_asset_preview_icon_id_request(&asset_library_ref, &asset)),
|
||||
asset_(asset)
|
||||
asset_identifier_(ED_asset_handle_get_identifier(&asset))
|
||||
{
|
||||
}
|
||||
|
||||
bool AssetGridViewItem::matches(const ui::AbstractGridViewItem &other) const
|
||||
{
|
||||
const AssetGridViewItem &other_item = dynamic_cast<const AssetGridViewItem &>(other);
|
||||
return StringRef(ED_asset_handle_get_identifier(&asset_)) ==
|
||||
StringRef(ED_asset_handle_get_identifier(&other_item.asset_));
|
||||
}
|
||||
|
||||
AssetHandle &AssetGridViewItem::get_asset()
|
||||
{
|
||||
return asset_;
|
||||
return asset_identifier_ == other_item.asset_identifier_;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
|
|
@ -53,14 +53,15 @@ class AssetGridView : public blender::ui::AbstractGridView {
|
|||
};
|
||||
|
||||
class AssetGridViewItem : public ui::PreviewGridItem {
|
||||
AssetHandle &asset_;
|
||||
/* Can't store this here, since the wrapped FileDirEntry will be freed while progressively
|
||||
* loading items. */
|
||||
// AssetHandle &asset_;
|
||||
std::string asset_identifier_;
|
||||
|
||||
public:
|
||||
AssetGridViewItem(const AssetLibraryReference &asset_library_ref, AssetHandle &);
|
||||
|
||||
bool matches(const AbstractGridViewItem &other) const override;
|
||||
|
||||
AssetHandle &get_asset();
|
||||
};
|
||||
|
||||
void asset_view_create_in_layout(const bContext &C,
|
||||
|
|
Loading…
Reference in New Issue