From de3d099d51126f27d553e6b33ba47e0825a3a01a Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Fri, 3 May 2024 08:53:18 +1000 Subject: [PATCH] catch image processing errors in font rendering think this was done before and accidentally undone --- source/rendering/StarFontTextureGroup.cpp | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/source/rendering/StarFontTextureGroup.cpp b/source/rendering/StarFontTextureGroup.cpp index 60f66f6..e312e8b 100644 --- a/source/rendering/StarFontTextureGroup.cpp +++ b/source/rendering/StarFontTextureGroup.cpp @@ -62,26 +62,36 @@ const FontTextureGroup::GlyphTexture& FontTextureGroup::glyphTexture(String::Cha Directives const& directives = *processingDirectives; Vec2F preSize = Vec2F(image.size()); + bool broken = false; for (auto& entry : directives->entries) { if (auto error = entry.operation.ptr()) { if (auto string = error->cause.ptr()) { if (!string->empty()) { - Logger::error("Error parsing font directives: {}", *string); + Logger::error("Error in parsed font directives: {}", *string); string->clear(); } } else if (auto& exception = error->cause.get()) { try { std::rethrow_exception(error->cause.get()); } catch (std::exception const& e) - { Logger::error("Exception parsing font directives: {}", e.what()); }; + { Logger::error("Exception in parsed font directives: {}", e.what()); }; exception = {}; } - image.forEachPixel([](unsigned x, unsigned y, Vec4B& pixel) { - pixel = ((x + y) % 2 == 0) ? Vec4B(255, 0, 255, pixel[3]) : Vec4B(0, 0, 0, pixel[3]); - }); - glyphTexture.colored = true; - } else - processImageOperation(entry.operation, image); + broken |= true; + } else { + try { processImageOperation(entry.operation, image); } + catch (StarException const& e) { + broken |= true; + Logger::error("Exception processing font directives for {}px '{}': {}", size, String(c), e.what()); + } + } + } + + if (broken) { + glyphTexture.colored = true; + image.forEachPixel([](unsigned x, unsigned y, Vec4B& pixel) { + pixel = ((x + y) % 2 == 0) ? Vec4B(255, 0, 255, pixel[3]) : Vec4B(0, 0, 0, pixel[3]); + }); } glyphTexture.offset = (preSize - Vec2F(image.size())) / 2;