fix background reloads

This commit is contained in:
Maximilian Seidler 2025-09-29 20:48:05 +02:00
parent b4b6eb7718
commit 2a93b2cb17
2 changed files with 13 additions and 12 deletions

View file

@ -251,10 +251,10 @@ bool CBackground::draw(const SRenderData& data) {
} }
void CBackground::onAssetUpdate(ResourceID id, ASP<CTexture> newAsset) { void CBackground::onAssetUpdate(ResourceID id, ASP<CTexture> newAsset) {
pendingResourceID = 0; pendingResource = false;
if (!newAsset) if (!newAsset)
Debug::log(ERR, "Background asset update failed, resourceID: {} not available on update!", pendingResourceID); Debug::log(ERR, "Background asset update failed, resourceID: {} not available on update!", id);
else if (newAsset->m_iType == TEXTURE_INVALID) { else if (newAsset->m_iType == TEXTURE_INVALID) {
g_asyncResourceManager->unload(newAsset); g_asyncResourceManager->unload(newAsset);
Debug::log(ERR, "New background asset has an invalid texture!"); Debug::log(ERR, "New background asset has an invalid texture!");
@ -264,14 +264,13 @@ void CBackground::onAssetUpdate(ResourceID id, ASP<CTexture> newAsset) {
*crossFadeProgress = 1.0; *crossFadeProgress = 1.0;
crossFadeProgress->setCallbackOnEnd( crossFadeProgress->setCallbackOnEnd(
[REF = m_self](auto) { [REF = m_self, id](auto) {
if (const auto PSELF = REF.lock()) { if (const auto PSELF = REF.lock()) {
if (PSELF->asset) if (PSELF->asset)
g_asyncResourceManager->unload(PSELF->asset); g_asyncResourceManager->unload(PSELF->asset);
PSELF->asset = PSELF->pendingAsset; PSELF->asset = PSELF->pendingAsset;
PSELF->pendingAsset = nullptr; PSELF->pendingAsset = nullptr;
PSELF->resourceID = PSELF->pendingResourceID; PSELF->resourceID = id;
PSELF->pendingResourceID = 0;
PSELF->blurredFB->destroyBuffer(); PSELF->blurredFB->destroyBuffer();
PSELF->blurredFB = std::move(PSELF->pendingBlurredFB); PSELF->blurredFB = std::move(PSELF->pendingBlurredFB);
@ -323,10 +322,12 @@ void CBackground::onReloadTimerUpdate() {
return; return;
} }
if (pendingResourceID > 0) if (pendingResource)
return; return;
pendingResource = true;
// Issue the next request // Issue the next request
AWP<IWidget> widget(m_self); AWP<IWidget> widget(m_self);
pendingResourceID = g_asyncResourceManager->requestImage(path, m_imageRevision, widget); g_asyncResourceManager->requestImage(path, m_imageRevision, widget);
} }

View file

@ -66,7 +66,7 @@ class CBackground : public IWidget {
ResourceID resourceID = 0; ResourceID resourceID = 0;
ResourceID scResourceID = 0; ResourceID scResourceID = 0;
ResourceID pendingResourceID = 0; bool pendingResource = false;
PHLANIMVAR<float> crossFadeProgress; PHLANIMVAR<float> crossFadeProgress;