VideoCommon: handle asset memory going over reserved limit correctly by erroring when the memory is exceeded and not allowing more assets to load until memory is released

This commit is contained in:
iwubcode
2023-12-21 00:55:51 -06:00
parent 70b7a59456
commit b669580aeb
2 changed files with 17 additions and 8 deletions

View File

@ -3,7 +3,6 @@
#include "VideoCommon/Assets/CustomAssetLoader.h"
#include "Common/Logging/Log.h"
#include "Common/MemoryUtil.h"
#include "VideoCommon/Assets/CustomAssetLibrary.h"
@ -48,19 +47,22 @@ void CustomAssetLoader::Init()
m_asset_load_thread.Reset("Custom Asset Loader", [this](std::weak_ptr<CustomAsset> asset) {
if (auto ptr = asset.lock())
{
if (m_memory_exceeded)
return;
if (ptr->Load())
{
std::lock_guard lk(m_asset_load_lock);
const std::size_t asset_memory_size = ptr->GetByteSizeInMemory();
if (m_max_memory_available >= m_total_bytes_loaded + asset_memory_size)
m_total_bytes_loaded += asset_memory_size;
m_assets_to_monitor.try_emplace(ptr->GetAssetId(), ptr);
if (m_total_bytes_loaded > m_max_memory_available)
{
m_total_bytes_loaded += asset_memory_size;
m_assets_to_monitor.try_emplace(ptr->GetAssetId(), ptr);
}
else
{
ERROR_LOG_FMT(VIDEO, "Failed to load asset {} because there was not enough memory.",
ERROR_LOG_FMT(VIDEO,
"Asset memory exceeded with asset '{}', future assets won't load until "
"memory is available.",
ptr->GetAssetId());
m_memory_exceeded = true;
}
}
}