From 8086d896e66398ddc07414346b4cbf550e14fe77 Mon Sep 17 00:00:00 2001 From: Maximilian Seidler <78690852+PaideiaDilemma@users.noreply.github.com> Date: Sat, 9 Mar 2024 17:45:44 +0100 Subject: [PATCH] background: handle missing assets (#158) * background: fix background not rendering when resource gatherer is busy * asyncResourceGatherer: check cairo_surface_status * background: clear resource id when texture is invalid --- src/renderer/AsyncResourceGatherer.cpp | 15 +++++++++++---- src/renderer/widgets/Background.cpp | 8 +++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/renderer/AsyncResourceGatherer.cpp b/src/renderer/AsyncResourceGatherer.cpp index a99131d..c9d81b8 100644 --- a/src/renderer/AsyncResourceGatherer.cpp +++ b/src/renderer/AsyncResourceGatherer.cpp @@ -167,10 +167,16 @@ void CAsyncResourceGatherer::apply() { std::lock_guard lg(asyncLoopState.assetsMutex); const auto ASSET = &assets[t.id]; - const auto CAIROFORMAT = cairo_image_surface_get_format((cairo_surface_t*)t.cairosurface); - const GLint glIFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_RGB32F : GL_RGBA; - const GLint glFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_RGB : GL_RGBA; - const GLint glType = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_FLOAT : GL_UNSIGNED_BYTE; + const auto SURFACESTATUS = cairo_surface_status((cairo_surface_t*)t.cairosurface); + const auto CAIROFORMAT = cairo_image_surface_get_format((cairo_surface_t*)t.cairosurface); + const GLint glIFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_RGB32F : GL_RGBA; + const GLint glFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_RGB : GL_RGBA; + const GLint glType = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_FLOAT : GL_UNSIGNED_BYTE; + + if (SURFACESTATUS != CAIRO_STATUS_SUCCESS) { + Debug::log(ERR, "Resource {} invalid ({})", t.id, cairo_status_to_string(SURFACESTATUS)); + ASSET->texture.m_iType = TEXTURE_INVALID; + } ASSET->texture.m_vSize = t.size; ASSET->texture.allocate(); @@ -186,6 +192,7 @@ void CAsyncResourceGatherer::apply() { cairo_destroy((cairo_t*)t.cairo); cairo_surface_destroy((cairo_surface_t*)t.cairosurface); + } else { Debug::log(ERR, "Unsupported type in ::apply() {}", (int)t.type); } diff --git a/src/renderer/widgets/Background.cpp b/src/renderer/widgets/Background.cpp index ed78b27..9a53bae 100644 --- a/src/renderer/widgets/Background.cpp +++ b/src/renderer/widgets/Background.cpp @@ -29,7 +29,13 @@ bool CBackground::draw(const SRenderData& data) { asset = g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID); if (!asset) - return false; + return true; + + if (asset->texture.m_iType == TEXTURE_INVALID) { + g_pRenderer->asyncResourceGatherer->unloadAsset(asset); + resourceID = ""; + return true; + } if ((blurPasses > 0 || isScreenshot) && !blurredFB.isAllocated()) { // make it brah