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
This commit is contained in:
Maximilian Seidler 2024-03-09 17:45:44 +01:00 committed by GitHub
parent 149b6737c2
commit 8086d896e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 5 deletions

View File

@ -167,10 +167,16 @@ void CAsyncResourceGatherer::apply() {
std::lock_guard<std::mutex> 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);
}

View File

@ -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