From c02ef4d7b99349f8e89315facdb9abe2289605e1 Mon Sep 17 00:00:00 2001 From: Ibrahn Sahir Date: Sat, 20 Oct 2018 10:13:06 +0100 Subject: [PATCH] Moved dynamic font list from static to lifetime controlled by main. Means the list is destroyed before the OS object, allowing it the opportunity to print an error if there are still dynamic font objects hanging around. (cherry picked from commit 7d82bed4f4cac8f5227d935c0496290e24eb48c8) --- scene/resources/dynamic_font.cpp | 20 +++++++++++--------- scene/resources/dynamic_font.h | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 1afeeb62287..8e85a78a476 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -960,7 +960,7 @@ void DynamicFont::_bind_methods() { Mutex *DynamicFont::dynamic_font_mutex = NULL; -SelfList::List DynamicFont::dynamic_fonts; +SelfList::List *DynamicFont::dynamic_fonts = NULL; DynamicFont::DynamicFont() : font_list(this) { @@ -969,29 +969,31 @@ DynamicFont::DynamicFont() : spacing_bottom = 0; spacing_char = 0; spacing_space = 0; - if (dynamic_font_mutex) + if (dynamic_font_mutex) { dynamic_font_mutex->lock(); - dynamic_fonts.add(&font_list); - if (dynamic_font_mutex) + dynamic_fonts->add(&font_list); dynamic_font_mutex->unlock(); + } } DynamicFont::~DynamicFont() { - - if (dynamic_font_mutex) + if (dynamic_font_mutex) { dynamic_font_mutex->lock(); - dynamic_fonts.remove(&font_list); - if (dynamic_font_mutex) + dynamic_fonts->remove(&font_list); dynamic_font_mutex->unlock(); + } } void DynamicFont::initialize_dynamic_fonts() { + dynamic_fonts = memnew(SelfList::List()); dynamic_font_mutex = Mutex::create(); } void DynamicFont::finish_dynamic_fonts() { memdelete(dynamic_font_mutex); dynamic_font_mutex = NULL; + memdelete(dynamic_fonts); + dynamic_fonts = NULL; } void DynamicFont::update_oversampling() { @@ -1001,7 +1003,7 @@ void DynamicFont::update_oversampling() { if (dynamic_font_mutex) dynamic_font_mutex->lock(); - SelfList *E = dynamic_fonts.first(); + SelfList *E = dynamic_fonts->first(); while (E) { if (E->self()->data_at_size.is_valid() && E->self()->data_at_size->update_oversampling()) { diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index 4182f249f0a..8ca95ab26a3 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -255,7 +255,7 @@ public: SelfList font_list; static Mutex *dynamic_font_mutex; - static SelfList::List dynamic_fonts; + static SelfList::List *dynamic_fonts; static void initialize_dynamic_fonts(); static void finish_dynamic_fonts();