From 63f6db2a0c590ae325ed5f1b3511da9044d6c612 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Fri, 7 Mar 2025 10:41:45 +0100 Subject: [PATCH] Fixed loading of multiple fonts by having one array per glyph range to keep it alive until the fonts are built. --- private/raid/application.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/private/raid/application.cpp b/private/raid/application.cpp index 0983476..92a656d 100644 --- a/private/raid/application.cpp +++ b/private/raid/application.cpp @@ -155,21 +155,23 @@ bool Application::loadFonts(std::span fonts) // by default ImGui takes ownership of the data, that's now what we want ImFontConfig config; config.FontDataOwnedByAtlas = false; - std::vector glyphRangesConverted; + std::vector> glyphRangesConverted; + glyphRangesConverted.reserve(fonts.size()); for (const auto& [font, data] : mijin::zip(fonts, buffers)) { ImWchar* glyphRanges = nullptr; if (!font.glyphRanges.empty()) { - glyphRangesConverted.reserve(2 * font.glyphRanges.size() + 1); - glyphRangesConverted.clear(); + std::vector& glyphData = glyphRangesConverted.emplace_back(); + glyphData.reserve(2 * font.glyphRanges.size() + 1); + glyphData.clear(); for (const std::pair& range : font.glyphRanges) { - glyphRangesConverted.push_back(range.first); - glyphRangesConverted.push_back(range.second); + glyphData.push_back(range.first); + glyphData.push_back(range.second); } - glyphRangesConverted.push_back(0); - glyphRanges = glyphRangesConverted.data(); + glyphData.push_back(0); + glyphRanges = glyphData.data(); } config.PixelSnapH = font.flags.pixelSnapH; imguiIO.Fonts->AddFontFromMemoryTTF(data.data(), static_cast(data.byteSize()), font.size, &config, glyphRanges);