Refactor: Assets: Use weak reference comparison to lookup assets
Comparing paths is tricky, especially when different operating systems are involved, with different slashes, encodings, etc. So often a string comparison is not good enough. Use asset weak reference comparison for this case, which performs more careful path comparisons. Not sure if this makes a difference in practice. But it might solve some subtle issues, and it makes some more sense semantically. So I think it's worth trying. Originally I was hoping this would fix #123508, but apparently didn't Pull Request: https://projects.blender.org/blender/blender/pulls/127685
This commit is contained in:
@@ -104,11 +104,9 @@ const asset_system::AssetRepresentation *find_asset_from_weak_ref(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const std::string full_path = all_library->resolve_asset_weak_reference_to_full_path(weak_ref);
|
||||
|
||||
const asset_system::AssetRepresentation *matching_asset = nullptr;
|
||||
list::iterate(library_ref, [&](asset_system::AssetRepresentation &asset) {
|
||||
if (asset.full_path() == full_path) {
|
||||
if (asset.make_weak_reference() == weak_ref) {
|
||||
matching_asset = &asset;
|
||||
return false;
|
||||
}
|
||||
@@ -117,6 +115,8 @@ const asset_system::AssetRepresentation *find_asset_from_weak_ref(
|
||||
|
||||
if (reports && !matching_asset) {
|
||||
if (list::is_loaded(&library_ref)) {
|
||||
const std::string full_path = all_library->resolve_asset_weak_reference_to_full_path(
|
||||
weak_ref);
|
||||
BKE_reportf(reports, RPT_ERROR, "No asset found at path \"%s\"", full_path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user