diff --git a/engine/src/flutter/third_party/txt/src/txt/font_collection.cc b/engine/src/flutter/third_party/txt/src/txt/font_collection.cc index 0c2d49f072..0fee4c7f82 100644 --- a/engine/src/flutter/third_party/txt/src/txt/font_collection.cc +++ b/engine/src/flutter/third_party/txt/src/txt/font_collection.cc @@ -30,6 +30,12 @@ namespace txt { +namespace { + +const std::shared_ptr g_null_family; + +} // anonymous namespace + bool FontCollection::FamilyKey::operator==( const FontCollection::FamilyKey& other) const { return font_family == other.font_family && locale == other.locale; @@ -50,11 +56,16 @@ class TxtFallbackFontProvider virtual const std::shared_ptr& matchFallbackFont( uint32_t ch, std::string locale) { - return font_collection_->MatchFallbackFont(ch, locale); + std::shared_ptr fc = font_collection_.lock(); + if (fc) { + return fc->MatchFallbackFont(ch, locale); + } else { + return g_null_family; + } } private: - std::shared_ptr font_collection_; + std::weak_ptr font_collection_; }; FontCollection::FontCollection() : enable_font_fallback_(true) {} @@ -199,7 +210,7 @@ const std::shared_ptr& FontCollection::MatchFallbackFont( return GetFallbackFontFamily(manager, family_name); } - return null_family_; + return g_null_family; } const std::shared_ptr& @@ -213,7 +224,7 @@ FontCollection::GetFallbackFontFamily(const sk_sp& manager, std::shared_ptr minikin_family = CreateMinikinFontFamily(manager, family_name); if (!minikin_family) - return null_family_; + return g_null_family; auto insert_it = fallback_fonts_.insert(std::make_pair(family_name, minikin_family)); diff --git a/engine/src/flutter/third_party/txt/src/txt/font_collection.h b/engine/src/flutter/third_party/txt/src/txt/font_collection.h index dd91a2a951..698eca1764 100644 --- a/engine/src/flutter/third_party/txt/src/txt/font_collection.h +++ b/engine/src/flutter/third_party/txt/src/txt/font_collection.h @@ -82,7 +82,6 @@ class FontCollection : public std::enable_shared_from_this { fallback_fonts_; std::unordered_map> fallback_fonts_for_locale_; - std::shared_ptr null_family_; bool enable_font_fallback_; std::vector> GetFontManagerOrder() const;