mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-11 17:17:42 +03:00
Fix TextLayout Cache not invalidating during Engine destroy (this generated crashes in the unit-tests).
This commit is contained in:
@@ -48,6 +48,7 @@ class EE_API TextLayout {
|
||||
LineWrapMode lineWrapMode = LineWrapMode::NoWrap, Uint32 wrapWidth = 0,
|
||||
bool keepIndentation = false, Float initialXOffset = 0 );
|
||||
|
||||
static void clearLayoutCache();
|
||||
protected:
|
||||
static void wrapLayout( const String::View& string, TextLayout&, LineWrapMode lineWrapMode,
|
||||
Float wrapWidth, Float vspace, bool keepIndentation, Font* font,
|
||||
|
||||
@@ -236,6 +236,17 @@ static inline Uint64 textLayoutHash( const String::View& string, Font* font,
|
||||
std::hash<Float>()( initialXOffset ) );
|
||||
}
|
||||
|
||||
static LRULayoutCache& getLayoutCache( bool invalidate = false ) {
|
||||
static LRULayoutCache sLayoutCache;
|
||||
if ( invalidate )
|
||||
sLayoutCache.clear();
|
||||
return sLayoutCache;
|
||||
}
|
||||
|
||||
void TextLayout::clearLayoutCache() {
|
||||
getLayoutCache( true );
|
||||
}
|
||||
|
||||
TextLayout::Cache TextLayout::layout( const String::View& string, Font* font,
|
||||
const Uint32& characterSize, const Uint32& style,
|
||||
const Uint32& tabWidth, const Float& outlineThickness,
|
||||
@@ -243,7 +254,6 @@ TextLayout::Cache TextLayout::layout( const String::View& string, Font* font,
|
||||
TextDirection baseDirection, LineWrapMode wrapMode,
|
||||
Uint32 wrapWidth, bool keepIndentation,
|
||||
Float initialXOffset ) {
|
||||
static LRULayoutCache sLayoutCache;
|
||||
|
||||
if ( !font || string.empty() ) {
|
||||
auto layout = std::make_shared<TextLayout>();
|
||||
@@ -258,7 +268,7 @@ TextLayout::Cache TextLayout::layout( const String::View& string, Font* font,
|
||||
tabOffset, baseDirection, wrapMode, wrapWidth, keepIndentation,
|
||||
initialXOffset );
|
||||
|
||||
auto cacheHit = sLayoutCache.get( hash );
|
||||
auto cacheHit = getLayoutCache().get( hash );
|
||||
if ( cacheHit.has_value() )
|
||||
return *cacheHit;
|
||||
}
|
||||
@@ -513,7 +523,7 @@ TextLayout::Cache TextLayout::layout( const String::View& string, Font* font,
|
||||
characterSize, style, tabWidth, outlineThickness, hspace );
|
||||
}
|
||||
|
||||
sLayoutCache.put( hash, resultPtr );
|
||||
getLayoutCache().put( hash, resultPtr );
|
||||
return resultPtr;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <eepp/graphics/ninepatchmanager.hpp>
|
||||
#include <eepp/graphics/renderer/renderer.hpp>
|
||||
#include <eepp/graphics/shaderprogrammanager.hpp>
|
||||
#include <eepp/graphics/textlayout.hpp>
|
||||
#include <eepp/graphics/textureatlasmanager.hpp>
|
||||
#include <eepp/graphics/texturefactory.hpp>
|
||||
#include <eepp/graphics/vertexbuffermanager.hpp>
|
||||
@@ -117,6 +118,8 @@ Engine::~Engine() {
|
||||
ParserMatcherManager::destroySingleton();
|
||||
|
||||
Log::destroySingleton();
|
||||
|
||||
TextLayout::clearLayoutCache();
|
||||
}
|
||||
|
||||
void Engine::destroy() {
|
||||
|
||||
Reference in New Issue
Block a user