diff --git a/common/font/outline_font.cpp b/common/font/outline_font.cpp index 6929822a54..3ec4dcf877 100644 --- a/common/font/outline_font.cpp +++ b/common/font/outline_font.cpp @@ -44,6 +44,7 @@ using namespace KIFONT; FT_Library OUTLINE_FONT::m_freeType = nullptr; +std::mutex OUTLINE_FONT::m_freeTypeMutex; OUTLINE_FONT::OUTLINE_FONT() : m_face(NULL), @@ -51,6 +52,8 @@ OUTLINE_FONT::OUTLINE_FONT() : m_fakeBold( false ), m_fakeItal( false ) { + std::lock_guard guard( m_freeTypeMutex ); + if( !m_freeType ) FT_Init_FreeType( &m_freeType ); } @@ -58,6 +61,8 @@ OUTLINE_FONT::OUTLINE_FONT() : wxString OUTLINE_FONT::FreeTypeVersion() { + std::lock_guard guard( m_freeTypeMutex ); + if( !m_freeType ) FT_Init_FreeType( &m_freeType ); @@ -118,6 +123,8 @@ OUTLINE_FONT* OUTLINE_FONT::LoadFont( const wxString& aFontName, bool aBold, boo FT_Error OUTLINE_FONT::loadFace( const wxString& aFontFileName ) { + std::lock_guard guard( m_freeTypeMutex ); + // TODO: check that going from wxString to char* with UTF-8 // conversion for filename makes sense on any/all platforms FT_Error e = FT_New_Face( m_freeType, aFontFileName.mb_str( wxConvUTF8 ), 0, &m_face ); @@ -369,7 +376,7 @@ VECTOR2I OUTLINE_FONT::getTextAsGlyphs( BOX2I* aBBox, std::vector #include +#include + namespace KIFONT { /** @@ -135,6 +137,7 @@ protected: private: // FreeType variables + static std::mutex m_freeTypeMutex; static FT_Library m_freeType; FT_Face m_face; const int m_faceSize;