Commit 84fdd7923c77ceed613bf13a83d2a2c016812c07

sammy 2009-07-19T16:09:40

Correct the order in which FT_Done_Face is called via the library's destructors. Fixes a Bzflag crash upon exit. Patch courtesy of Mathew Eis (kingrobot) from SF patch 2721799.

diff --git a/msvc/vc71/ftgl_dll.vcproj b/msvc/vc71/ftgl_dll.vcproj
index f7e6cb0..e3e2b97 100644
--- a/msvc/vc71/ftgl_dll.vcproj
+++ b/msvc/vc71/ftgl_dll.vcproj
@@ -142,6 +142,9 @@
 				RelativePath="..\..\src\FTCharmap.cpp">
 			</File>
 			<File
+				RelativePath="..\..\src\FTCleanup.cpp">
+			</File>
+			<File
 				RelativePath="..\..\src\FTContour.cpp">
 			</File>
 			<File
@@ -252,6 +255,9 @@
 				RelativePath="..\..\src\FTCharToGlyphIndexMap.h">
 			</File>
 			<File
+				RelativePath="..\..\src\FTCleanup.h">
+			</File>
+			<File
 				RelativePath="..\..\src\FTContour.h">
 			</File>
 			<File
diff --git a/msvc/vc8/ftgl_dll.vcproj b/msvc/vc8/ftgl_dll.vcproj
index 8d10fbd..cacdda6 100644
--- a/msvc/vc8/ftgl_dll.vcproj
+++ b/msvc/vc8/ftgl_dll.vcproj
@@ -224,6 +224,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\FTCleanup.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\FTContour.cpp"
 				>
 			</File>
@@ -357,6 +361,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\FTCleanup.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\FTContour.h"
 				>
 			</File>
diff --git a/msvc/vc8/ftgl_static.vcproj b/msvc/vc8/ftgl_static.vcproj
index d88f354..a83c9e2 100644
--- a/msvc/vc8/ftgl_static.vcproj
+++ b/msvc/vc8/ftgl_static.vcproj
@@ -159,6 +159,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\FTCleanup.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\FTContour.cpp"
 				>
 			</File>
@@ -297,6 +301,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\FTCleanup.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\FTContour.h"
 				>
 			</File>
diff --git a/msvc/vc9/ftgl_dll.vcproj b/msvc/vc9/ftgl_dll.vcproj
index 10c9218..0965a9d 100644
--- a/msvc/vc9/ftgl_dll.vcproj
+++ b/msvc/vc9/ftgl_dll.vcproj
@@ -225,6 +225,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\FTCleanup.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\FTContour.cpp"
 				>
 			</File>
@@ -358,6 +362,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\FTCleanup.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\FTContour.h"
 				>
 			</File>
diff --git a/msvc/vc9/ftgl_static.vcproj b/msvc/vc9/ftgl_static.vcproj
index 24eba13..d52541e 100644
--- a/msvc/vc9/ftgl_static.vcproj
+++ b/msvc/vc9/ftgl_static.vcproj
@@ -160,6 +160,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\FTCleanup.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\FTContour.cpp"
 				>
 			</File>
@@ -298,6 +302,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\src\FTCleanup.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\src\FTContour.h"
 				>
 			</File>
diff --git a/src/FTFace.cpp b/src/FTFace.cpp
index 30f9793..eb6ffff 100644
--- a/src/FTFace.cpp
+++ b/src/FTFace.cpp
@@ -27,6 +27,7 @@
 #include "config.h"
 
 #include "FTFace.h"
+#include "FTCleanup.h"
 #include "FTLibrary.h"
 
 #include FT_TRUETYPE_TABLES_H
@@ -49,6 +50,8 @@ FTFace::FTFace(const char* fontFilePath, bool precomputeKerning)
         return;
     }
 
+    FTCleanup::Instance()->RegisterObject(&ftFace);
+
     numGlyphs = (*ftFace)->num_glyphs;
     hasKerningTable = (FT_HAS_KERNING((*ftFace)) != 0);
 
@@ -79,6 +82,8 @@ FTFace::FTFace(const unsigned char *pBufferBytes, size_t bufferSizeInBytes,
         return;
     }
 
+    FTCleanup::Instance()->RegisterObject(&ftFace);
+
     numGlyphs = (*ftFace)->num_glyphs;
     hasKerningTable = (FT_HAS_KERNING((*ftFace)) != 0);
 
@@ -95,6 +100,8 @@ FTFace::~FTFace()
 
     if(ftFace)
     {
+        FTCleanup::Instance()->UnregisterObject(&ftFace);
+
         FT_Done_Face(*ftFace);
         delete ftFace;
         ftFace = 0;
diff --git a/src/FTLibrary.cpp b/src/FTLibrary.cpp
index 829ed59..da16e83 100644
--- a/src/FTLibrary.cpp
+++ b/src/FTLibrary.cpp
@@ -26,7 +26,7 @@
 #include "config.h"
 
 #include "FTLibrary.h"
-
+#include "FTCleanup.h"
 
 const FTLibrary&  FTLibrary::Instance()
 {
@@ -37,6 +37,8 @@ const FTLibrary&  FTLibrary::Instance()
 
 FTLibrary::~FTLibrary()
 {
+    FTCleanup::Instance()->DestroyAll();
+
     if(library != 0)
     {
         FT_Done_FreeType(*library);
@@ -70,5 +72,7 @@ bool FTLibrary::Initialise()
         return false;
     }
 
+    FTCleanup::Instance();
+
     return true;
 }
diff --git a/src/Makefile.am b/src/Makefile.am
index 941b0cd..1cf74e5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,6 +6,8 @@ libftgl_la_SOURCES = \
     FTCharmap.cpp \
     FTCharmap.h \
     FTCharToGlyphIndexMap.h \
+    FTCleanup.cpp \
+    FTCleanup.h \
     FTContour.cpp \
     FTContour.h \
     FTFace.cpp \