From 420d0daf28853e1db1a985f9a74ec38f3d978ddc Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 22 Jul 2026 22:48:16 +0300 Subject: [PATCH] fix: missing font usage produces fatal error --- src/graphics/core/FontMetics.hpp | 4 ++-- src/graphics/ui/elements/Label.cpp | 3 +++ src/graphics/ui/elements/TextBox.cpp | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/graphics/core/FontMetics.hpp b/src/graphics/core/FontMetics.hpp index a835a495b..d62a105d9 100644 --- a/src/graphics/core/FontMetics.hpp +++ b/src/graphics/core/FontMetics.hpp @@ -9,8 +9,8 @@ class Font; struct FontMetrics { std::optional> font; - int lineHeight; - int yoffset; + int lineHeight = 0; + int yoffset = 0; int _glyphInterval = 8; ~FontMetrics(); diff --git a/src/graphics/ui/elements/Label.cpp b/src/graphics/ui/elements/Label.cpp index 14cbeea2d..effb79830 100644 --- a/src/graphics/ui/elements/Label.cpp +++ b/src/graphics/ui/elements/Label.cpp @@ -207,6 +207,9 @@ uint Label::getLinesNumber() const { void Label::draw(const DrawContext& pctx, const Assets& assets) { auto batch = pctx.getBatch2D(); auto font = assets.getShared(fontName); + if (font == nullptr) { + return; + } cache.prepare( font, font->getMetrics(), diff --git a/src/graphics/ui/elements/TextBox.cpp b/src/graphics/ui/elements/TextBox.cpp index d04ca5786..f37673fc1 100644 --- a/src/graphics/ui/elements/TextBox.cpp +++ b/src/graphics/ui/elements/TextBox.cpp @@ -353,7 +353,9 @@ void TextBox::draw(const DrawContext& pctx, const Assets& assets) { void TextBox::drawBackground(const DrawContext& pctx, const Assets& assets) { auto font = assets.getShared(label->getFontName()); - rawTextCache.prepare(font, font->getMetrics(), label->getSize().x); + if (font != nullptr) { + rawTextCache.prepare(font, font->getMetrics(), label->getSize().x); + } glm::vec2 pos = calcPos();