From cdc1346612ab5dca28fcc63e6437fb1822790290 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Thu, 11 Feb 2010 08:31:52 +0000 Subject: [PATCH] FS#152 - Fix crash with the default font at global exit on Windows git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1401 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Graphics/Font.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index df2e5633..36c4c280 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -158,14 +158,28 @@ const Image& Font::GetImage() const //////////////////////////////////////////////////////////// const Font& Font::GetDefaultFont() { - static Font DefaultFont; - static bool DefaultFontLoaded = false; +#if defined(SFML_SYSTEM_WINDOWS) && defined(SFML_DYNAMIC) + + // On Windows dynamic build, the default font causes a crash at global exit. + // This is a temporary workaround that turns the crash into a memory leak. + // Note that this bug doesn't exist anymore in SFML 2. + static Font* DefaultFontPtr = new Font; + Font& DefaultFont = *DefaultFontPtr; + +#else + + static Font DefaultFont; + +#endif + + // Get the raw data of the Arial font file into an array, so that we can load it into the font static const char DefaultFontData[] = { #include }; // Load the default font on first call + static bool DefaultFontLoaded = false; if (!DefaultFontLoaded) { DefaultFont.LoadFromMemory(DefaultFontData, sizeof(DefaultFontData), 30);