From f927c15adffcb3ef4e06667773363d7460af0735 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 23 Feb 2023 14:58:37 -0800 Subject: [PATCH] Prevent mutex deadlock The overbar function in outline fonts recursively calls the text function which already owns the lock. To avoid this, we have an unlocked variant that is wrapped by the exposed text function Fixes https://gitlab.com/kicad/code/kicad/issues/14015 (cherry picked from commit 81256c0fa4449ce886f3668c02f76cca861b4d94) --- common/font/outline_font.cpp | 16 +++++++++++++--- include/font/outline_font.h | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/common/font/outline_font.cpp b/common/font/outline_font.cpp index 638baab88a..497495ed38 100644 --- a/common/font/outline_font.cpp +++ b/common/font/outline_font.cpp @@ -334,9 +334,19 @@ VECTOR2I OUTLINE_FONT::getTextAsGlyphs( BOX2I* aBBox, std::vector guard( m_freeTypeMutex ); + + return getTextAsGlyphsUnlocked( aBBox, aGlyphs, aText, aSize, aPosition, aAngle, aMirror, + aOrigin, aTextStyle ); +} + +VECTOR2I OUTLINE_FONT::getTextAsGlyphsUnlocked( BOX2I* aBBox, std::vector>* aGlyphs, + const wxString& aText, const VECTOR2I& aSize, + const VECTOR2I& aPosition, const EDA_ANGLE& aAngle, + bool aMirror, const VECTOR2I& aOrigin, + TEXT_STYLE_FLAGS aTextStyle ) const +{ + VECTOR2D glyphSize = aSize; FT_Face face = m_face; double scaler = faceSize(); @@ -478,7 +488,7 @@ VECTOR2I OUTLINE_FONT::getTextAsGlyphs( BOX2I* aBBox, std::vector> underscoreGlyphs; - getTextAsGlyphs( nullptr, &underscoreGlyphs, wxT( "_" ), aSize, { 0, 0 }, ANGLE_0, false, + getTextAsGlyphsUnlocked( nullptr, &underscoreGlyphs, wxT( "_" ), aSize, { 0, 0 }, ANGLE_0, false, { 0, 0 }, aTextStyle & ~TEXT_STYLE::OVERBAR ); OUTLINE_GLYPH* underscoreGlyph = static_cast( underscoreGlyphs[0].get() ); diff --git a/include/font/outline_font.h b/include/font/outline_font.h index 0ccf703920..d04ce98d28 100644 --- a/include/font/outline_font.h +++ b/include/font/outline_font.h @@ -135,6 +135,12 @@ protected: const VECTOR2I& aPosition, const EDA_ANGLE& aAngle, bool aMirror, const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const; +private: + VECTOR2I getTextAsGlyphsUnlocked( BOX2I* aBoundingBox, std::vector>* aGlyphs, + const wxString& aText, const VECTOR2I& aSize, + const VECTOR2I& aPosition, const EDA_ANGLE& aAngle, bool aMirror, + const VECTOR2I& aOrigin, TEXT_STYLE_FLAGS aTextStyle ) const; + private: // FreeType variables