Merge pull request #11912 from iwubcode/asset_error_checking

VideoCommon: add additional error logs for asset loading and don't crash when asset no longer exists on reload
This commit is contained in:
Admiral H. Curtiss 2023-06-09 13:39:59 +02:00 committed by GitHub
commit e16791f2ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 4 deletions

View File

@ -4,6 +4,7 @@
#include "VideoCommon/Assets/DirectFilesystemAssetLibrary.h" #include "VideoCommon/Assets/DirectFilesystemAssetLibrary.h"
#include <algorithm> #include <algorithm>
#include <fmt/os.h>
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
@ -35,7 +36,10 @@ DirectFilesystemAssetLibrary::GetLastAssetWriteTime(const AssetID& asset_id) con
CustomAssetLibrary::TimeType max_entry; CustomAssetLibrary::TimeType max_entry;
for (const auto& [key, value] : asset_map_path) for (const auto& [key, value] : asset_map_path)
{ {
const auto tp = std::filesystem::last_write_time(value); std::error_code ec;
const auto tp = std::filesystem::last_write_time(value, ec);
if (ec)
continue;
if (tp > max_entry) if (tp > max_entry)
max_entry = tp; max_entry = tp;
} }
@ -52,17 +56,31 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const Ass
// Raw texture is expected to have one asset mapped // Raw texture is expected to have one asset mapped
if (asset_map.empty() || asset_map.size() > 1) if (asset_map.empty() || asset_map.size() > 1)
{
ERROR_LOG_FMT(VIDEO, "Asset '{}' error - raw texture expected to have one file mapped!",
asset_id);
return {}; return {};
}
const auto& asset_path = asset_map.begin()->second; const auto& asset_path = asset_map.begin()->second;
const auto last_loaded_time = std::filesystem::last_write_time(asset_path); std::error_code ec;
const auto last_loaded_time = std::filesystem::last_write_time(asset_path, ec);
if (ec)
{
ERROR_LOG_FMT(VIDEO, "Asset '{}' error - failed to get last write time with error '{}'!",
asset_id, ec);
return {};
}
auto ext = asset_path.extension().string(); auto ext = asset_path.extension().string();
Common::ToLower(&ext); Common::ToLower(&ext);
if (ext == ".dds") if (ext == ".dds")
{ {
LoadDDSTexture(data, asset_path.string()); if (!LoadDDSTexture(data, asset_path.string()))
if (data->m_levels.empty()) [[unlikely]] {
ERROR_LOG_FMT(VIDEO, "Asset '{}' error - could not load dds texture!", asset_id);
return {}; return {};
}
if (!LoadMips(asset_path, data)) if (!LoadMips(asset_path, data))
return {}; return {};
@ -75,13 +93,18 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const Ass
data->m_levels.push_back({}); data->m_levels.push_back({});
if (!LoadPNGTexture(&data->m_levels[0], asset_path.string())) if (!LoadPNGTexture(&data->m_levels[0], asset_path.string()))
{
ERROR_LOG_FMT(VIDEO, "Asset '{}' error - could not load png texture!", asset_id);
return {}; return {};
}
if (!LoadMips(asset_path, data)) if (!LoadMips(asset_path, data))
return {}; return {};
return LoadInfo{GetAssetSize(*data), last_loaded_time}; return LoadInfo{GetAssetSize(*data), last_loaded_time};
} }
ERROR_LOG_FMT(VIDEO, "Asset '{}' error - extension '{}' unknown!", asset_id, ext);
return {}; return {};
} }