Destructor order fix

This commit is contained in:
Jack Andersen 2015-11-22 13:51:44 -10:00
parent 2c138d138e
commit 02cfa7ec74
2 changed files with 19 additions and 13 deletions

View File

@ -34,12 +34,17 @@ class FontAtlas
class FontCache
{
const HECL::Runtime::FileStoreManager& m_fileMgr;
FT_Library m_fontLib;
struct Library
{
FT_Library m_lib;
Library();
~Library();
operator FT_Library() {return m_lib;}
} m_fontLib;
FreeTypeGZipMemFace m_regFace;
FreeTypeGZipMemFace m_monoFace;
public:
FontCache(const HECL::Runtime::FileStoreManager& fileMgr);
~FontCache();
FontHandle prepMainFont(float points=10.0);
FontHandle prepMonoFont(float points=10.0);

View File

@ -36,17 +36,23 @@ FreeTypeGZipMemFace::FreeTypeGZipMemFace(FT_Library lib, const uint8_t* data, si
if (FT_Open_Face(lib, &args, 0, &m_face))
Log.report(LogVisor::FatalError, "unable to open FreeType gzip face");
FT_Done_Face(m_face);
if (m_decomp.close)
m_decomp.close(&m_decomp);
}
FreeTypeGZipMemFace::~FreeTypeGZipMemFace()
{
FT_Done_Face(m_face);
if (m_decomp.close)
m_decomp.close(&m_decomp);
}
FontCache::Library::Library()
{
FT_Error err = FT_Init_FreeType(&m_lib);
if (err)
Log.report(LogVisor::FatalError, "unable to FT_Init_FreeType");
}
FontCache::Library::~Library()
{
FT_Done_FreeType(m_lib);
}
static FT_Library InitLib()
@ -60,13 +66,8 @@ static FT_Library InitLib()
FontCache::FontCache(const HECL::Runtime::FileStoreManager& fileMgr)
: m_fileMgr(fileMgr),
m_fontLib(InitLib()),
m_regFace(m_fontLib, DROIDSANS_PERMISSIVE, DROIDSANS_PERMISSIVE_SZ),
m_monoFace(m_fontLib, BMONOFONT, BMONOFONT_SZ) {}
FontCache::~FontCache()
{
FT_Done_FreeType(m_fontLib);
}
}