summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-07-07 12:07:06 +0000
committerfrosch <frosch@openttd.org>2013-07-07 12:07:06 +0000
commit0c0db5c4c7f509ac631dacd9375e007388abcf92 (patch)
treeedcce40769215535446efafa44af5dd0cb9e6436 /src
parent51f0d11ee3a5cd7b31fcf575424e228d4e69eaa5 (diff)
downloadopenttd-0c0db5c4c7f509ac631dacd9375e007388abcf92.tar.xz
(svn r25574) -Fix (r25570): Trouble with initialisation order of static members of Layouter and FontCache.
Diffstat (limited to 'src')
-rw-r--r--src/gfx_layout.cpp17
-rw-r--r--src/gfx_layout.h2
2 files changed, 13 insertions, 6 deletions
diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp
index 01be1e014..b47709374 100644
--- a/src/gfx_layout.cpp
+++ b/src/gfx_layout.cpp
@@ -22,7 +22,7 @@
/** Cache of ParagraphLayout lines. */
-Layouter::LineCache Layouter::linecache;
+Layouter::LineCache *Layouter::linecache;
/** Cache of Font instances. */
Layouter::FontColourMap Layouter::fonts[FS_END];
@@ -550,10 +550,15 @@ void Layouter::ResetFontCache(FontSize size)
*/
Layouter::LineCacheItem &Layouter::GetCachedParagraphLayout(const char *str, size_t len, const FontState &state)
{
+ if (linecache == NULL) {
+ /* Create linecache on first access to avoid trouble with initialisation order of static variables. */
+ linecache = new LineCache();
+ }
+
LineCacheKey key;
key.state_before = state;
key.str.assign(str, len);
- return linecache[key];
+ return (*linecache)[key];
}
/**
@@ -561,7 +566,7 @@ Layouter::LineCacheItem &Layouter::GetCachedParagraphLayout(const char *str, siz
*/
void Layouter::ResetLineCache()
{
- linecache.clear();
+ if (linecache != NULL) linecache->clear();
}
/**
@@ -569,6 +574,8 @@ void Layouter::ResetLineCache()
*/
void Layouter::ReduceLineCache()
{
- /* TODO LRU cache would be fancy, but not exactly necessary */
- if (linecache.size() > 4096) ResetLineCache();
+ if (linecache != NULL) {
+ /* TODO LRU cache would be fancy, but not exactly necessary */
+ if (linecache->size() > 4096) ResetLineCache();
+ }
}
diff --git a/src/gfx_layout.h b/src/gfx_layout.h
index 1215954cb..c252d15eb 100644
--- a/src/gfx_layout.h
+++ b/src/gfx_layout.h
@@ -198,7 +198,7 @@ class Layouter : public AutoDeleteSmallVector<ParagraphLayout::Line *, 4> {
~LineCacheItem() { delete layout; }
};
typedef std::map<LineCacheKey, LineCacheItem> LineCache;
- static LineCache linecache;
+ static LineCache *linecache;
static LineCacheItem &GetCachedParagraphLayout(const char *str, size_t len, const FontState &state);