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) {
pendingResourceID = 0;
pendingResource = false;
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) {
g_asyncResourceManager->unload(newAsset);
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->setCallbackOnEnd(
[REF = m_self](auto) {
[REF = m_self, id](auto) {
if (const auto PSELF = REF.lock()) {
if (PSELF->asset)
g_asyncResourceManager->unload(PSELF->asset);
PSELF->asset = PSELF->pendingAsset;
PSELF->pendingAsset = nullptr;
PSELF->resourceID = PSELF->pendingResourceID;
PSELF->pendingResourceID = 0;
PSELF->asset = PSELF->pendingAsset;
PSELF->pendingAsset = nullptr;
PSELF->resourceID = id;
PSELF->blurredFB->destroyBuffer();
PSELF->blurredFB = std::move(PSELF->pendingBlurredFB);
@ -323,10 +322,12 @@ void CBackground::onReloadTimerUpdate() {
return;
}
if (pendingResourceID > 0)
if (pendingResource)
return;
pendingResource = true;
// Issue the next request
AWP<IWidget> widget(m_self);
pendingResourceID = g_asyncResourceManager->requestImage(path, m_imageRevision, widget);
g_asyncResourceManager->requestImage(path, m_imageRevision, widget);
}

View file

@ -64,9 +64,9 @@ class CBackground : public IWidget {
std::string outputPort;
Hyprutils::Math::eTransform transform;
ResourceID resourceID = 0;
ResourceID scResourceID = 0;
ResourceID pendingResourceID = 0;
ResourceID resourceID = 0;
ResourceID scResourceID = 0;
bool pendingResource = false;
PHLANIMVAR<float> crossFadeProgress;