From 62337f75b8b6c3dcabe13880adb5a872c42a9440 Mon Sep 17 00:00:00 2001 From: Mark Roszko Date: Fri, 17 Feb 2023 14:39:52 +0000 Subject: [PATCH] FT_Face is also not thread, protect getTextAsGlyphs (cherry picked from commit 7b4abb1f7b6ceb17c39a0d97f68b2fa7bf258921) --- common/font/outline_font.cpp | 5 +++++ include/font/outline_font.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/common/font/outline_font.cpp b/common/font/outline_font.cpp index 3ec4dcf877..638baab88a 100644 --- a/common/font/outline_font.cpp +++ b/common/font/outline_font.cpp @@ -335,6 +335,8 @@ VECTOR2I OUTLINE_FONT::getTextAsGlyphs( BOX2I* aBBox, std::vector guard( m_freeTypeMutex ); FT_Face face = m_face; double scaler = faceSize(); @@ -562,6 +564,9 @@ void OUTLINE_FONT::RenderToOpenGLCanvas( KIGFX::OPENGL_GAL& aGal, const wxString unsigned int glyphCount; hb_glyph_info_t* glyphInfo = hb_buffer_get_glyph_infos( buf, &glyphCount ); hb_glyph_position_t* glyphPos = hb_buffer_get_glyph_positions( buf, &glyphCount ); + + std::lock_guard guard( m_freeTypeMutex ); + hb_font_t* referencedFont = hb_ft_font_create_referenced( m_face ); hb_ft_font_set_funcs( referencedFont ); diff --git a/include/font/outline_font.h b/include/font/outline_font.h index 82af25ec34..0ccf703920 100644 --- a/include/font/outline_font.h +++ b/include/font/outline_font.h @@ -137,9 +137,14 @@ protected: private: // FreeType variables + + /** + * Mutex for freetype access, FT_Library and FT_Face are not thread safe + */ static std::mutex m_freeTypeMutex; static FT_Library m_freeType; FT_Face m_face; + const int m_faceSize; bool m_fakeBold; bool m_fakeItal;