From e1835327471e1b839daaf432a66ee80c31f0d161 Mon Sep 17 00:00:00 2001 From: zetaPRIME Date: Thu, 11 May 2017 17:42:07 -0400 Subject: [PATCH] added FontNull, should hopefully prevent crashes from trying to load fonts with no fallback --- .../source/starlight/ThemeManager.cpp | 5 +++++ libstarlight/source/starlight/gfx/Font.h | 2 -- libstarlight/source/starlight/gfx/FontNull.h | 21 +++++++++++++++++++ libstarlight/todo.txt | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 libstarlight/source/starlight/gfx/FontNull.h diff --git a/libstarlight/source/starlight/ThemeManager.cpp b/libstarlight/source/starlight/ThemeManager.cpp index 94220c2..bb80fba 100644 --- a/libstarlight/source/starlight/ThemeManager.cpp +++ b/libstarlight/source/starlight/ThemeManager.cpp @@ -19,6 +19,7 @@ #include "starlight/gfx/DrawableNinePatch.h" #include "starlight/gfx/DrawableTest.h" #include "starlight/gfx/FontBMF.h" +#include "starlight/gfx/FontNull.h" #include "starlight/gfx/RenderCore.h" #include "starlight/gfx/BitmapFont.h" @@ -264,6 +265,10 @@ shared_ptr ThemeManager::LoadAsset(string& path, ThemeRefContainer& ref) { string path = ResolveFontPath(ref.name); + if (path == "") { // no fonts found, emergency fallback + ref.ptr = make_shared(); + return; + } auto font = make_shared(); { // using: json j; diff --git a/libstarlight/source/starlight/gfx/Font.h b/libstarlight/source/starlight/gfx/Font.h index 7995180..6470fd4 100644 --- a/libstarlight/source/starlight/gfx/Font.h +++ b/libstarlight/source/starlight/gfx/Font.h @@ -14,8 +14,6 @@ namespace starlight { namespace gfx { class Font { public: - static constexpr const int defaultSize = 16; - Font() { } virtual ~Font() { } diff --git a/libstarlight/source/starlight/gfx/FontNull.h b/libstarlight/source/starlight/gfx/FontNull.h new file mode 100644 index 0000000..d300084 --- /dev/null +++ b/libstarlight/source/starlight/gfx/FontNull.h @@ -0,0 +1,21 @@ +#pragma once +#include "starlight/_global.h" + +namespace starlight { + namespace gfx { + class FontNull : public Font { + public: + FontNull() { } + ~FontNull() override { } + + void Print(Vector2 position, const std::string& text, float scale = 1, Color color = Color::white, Vector2 justification = Vector2::zero, OptRef borderColor = nullptr) override {} + void Print(VRect rect, const std::string& text, float scale = 1, Color color = Color::white, Vector2 justification = Vector2::zero, OptRef borderColor = nullptr) override {} + + Vector2 Measure(const std::string& text, float scale = 1, float maxWidth = 400) override { return Vector2::zero; } + + Vector2 GetCursorPosition(VRect rect, const std::string& text, unsigned int end, float scale = 1) override { return Vector2::zero; } + unsigned int GetCursorFromPoint(VRect rect, const std::string& text, Vector2 pt, float scale = 1) override { return Vector2::zero; } + }; + + } +} diff --git a/libstarlight/todo.txt b/libstarlight/todo.txt index da84d88..4a914d2 100644 --- a/libstarlight/todo.txt +++ b/libstarlight/todo.txt @@ -2,7 +2,7 @@ roadmap to v0.5.1 { - make font-not-found not outright crash the app + - make font-not-found not outright crash the app (hopefully) make asset gc actually sweep every 5sec maybe entirely replace clearing with transparent knockout on bind? implement more blend modes??