From 9b102ba88ab121623dfb43da247c401a73aecc85 Mon Sep 17 00:00:00 2001 From: Vincent Hengel Date: Wed, 16 Sep 2026 20:20:43 +0200 Subject: [PATCH] fix(ui): take the splash font from memory, and for ocean_fft Two portability fixes that have nothing to do with each other beyond both being one-liners in the same tree. The splash wrote Roboto to a temp file and handed ultragui the path, because FT_New_Face was the only way into its text engine. The file needed a name no concurrent process would also pick, so it carried ::getpid() -- and that single call dragged into the module, which MSVC does not have. A windows build of anything linking rx::ui fails on the include. libultragui grew LoadFontMemory (Force67/libultragui#5), so the bytes from rx_fonts.rxp go straight in. The temp path, the pid, the write, the unlink in Shutdown and font_cache_path_ all go with it; a splash that fails to find its font still falls back to a system one. ocean_fft.cc calls std::memcpy and never included ; it arrived transitively through equilibrium's headers until equilibrium removed the STL from base's production surface. Include it where it is used. --- engine/render/geometry/ocean_fft.cc | 1 + engine/ui/splash.cc | 33 ++++++----------------------- engine/ui/splash.h | 3 --- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/engine/render/geometry/ocean_fft.cc b/engine/render/geometry/ocean_fft.cc index be734e10..fbb95f9b 100644 --- a/engine/render/geometry/ocean_fft.cc +++ b/engine/render/geometry/ocean_fft.cc @@ -1,6 +1,7 @@ #include "render/geometry/ocean_fft.h" #include +#include #include #include diff --git a/engine/ui/splash.cc b/engine/ui/splash.cc index a8ba11d6..cc11db56 100644 --- a/engine/ui/splash.cc +++ b/engine/ui/splash.cc @@ -1,12 +1,8 @@ #include "ui/splash.h" -#include - -#include #include #include #include -#include #include #include @@ -33,9 +29,8 @@ namespace fs = std::filesystem; constexpr f32 kLogoHeightFraction = 0.26f; constexpr f32 kLogoWidthFraction = 0.52f; -// ultragui's TextEngine opens fonts by path (FT_New_Face), and rx ships Roboto -// inside rx_fonts.rxp, so the bytes have no path of their own. Mirror them into -// one file under the temp dir; Shutdown removes it again. +// rx ships Roboto inside rx_fonts.rxp, so the face has no path of its own and +// is handed to ultragui as bytes (LoadFontMemory, which keeps its own copy). constexpr const char* kFontAsset = "fonts://roboto/Roboto-Medium.ttf"; // A font on the machine, for a tree whose rx_fonts.rxp was never packed. The @@ -159,20 +154,11 @@ bool Splash::Initialize(Window& window, render::Renderer& renderer, asset::Vfs& bool Splash::LoadFont(asset::Vfs& vfs) { if (std::optional> bytes = vfs.Read(kFontAsset)) { - std::error_code ec; - fs::path path = fs::temp_directory_path(ec) / - ("rx-splash-" + std::to_string(::getpid()) + ".ttf"); - if (!ec) { - if (std::FILE* f = std::fopen(path.c_str(), "wb")) { - const std::size_t written = std::fwrite(bytes->data(), 1, bytes->size(), f); - std::fclose(f); - if (written == bytes->size()) { - font_cache_path_ = path.string(); - ui_->set_default_font(ui_->LoadFont(font_cache_path_.c_str())); - return true; - } - fs::remove(path, ec); - } + const ugui::FontHandle font = ui_->LoadFontMemory( + reinterpret_cast(bytes->data()), bytes->size()); + if (font != ugui::kInvalidFont) { + ui_->set_default_font(font); + return true; } } if (const char* system = SystemFont()) { @@ -370,11 +356,6 @@ void Splash::Shutdown() { park_.reset(); // before ui_: ScopedActive restores in reverse order ui_.reset(); } - if (!font_cache_path_.empty()) { - std::error_code ec; - fs::remove(font_cache_path_, ec); - font_cache_path_.clear(); - } draw_data_ = nullptr; ready_ = false; } diff --git a/engine/ui/splash.h b/engine/ui/splash.h index d43690ac..dd289835 100644 --- a/engine/ui/splash.h +++ b/engine/ui/splash.h @@ -2,7 +2,6 @@ #define RX_UI_SPLASH_H_ #include -#include #include @@ -103,8 +102,6 @@ class RX_UI_EXPORT Splash { // canvas. BuildDocument measures the draw box from it, so the two cannot // drift apart without the wordmark stretching to cover the difference. f32 logo_aspect_ = 1.0f; - // Deleted in Shutdown; empty when the font came from the system instead. - std::string font_cache_path_; f32 total_seconds_ = kDefaultSeconds; f32 elapsed_ = 0.0f;