diff --git a/specter/include/specter/ViewResources.hpp b/specter/include/specter/ViewResources.hpp index e9ae3fb9c..df12a1fcc 100644 --- a/specter/include/specter/ViewResources.hpp +++ b/specter/include/specter/ViewResources.hpp @@ -179,8 +179,8 @@ public: specter::FontTag m_curveFont; std::thread m_fcacheThread; - bool m_fcacheInterrupt = false; - bool m_fcacheReady = false; + std::atomic_bool m_fcacheInterrupt = {false}; + std::atomic_bool m_fcacheReady = {false}; ViewResources() = default; ViewResources(const ViewResources& other) = delete; @@ -198,7 +198,7 @@ public: { if (m_fcacheThread.joinable()) { - m_fcacheInterrupt = true; + m_fcacheInterrupt.store(true); m_fcacheThread.join(); } } @@ -207,7 +207,7 @@ public: void destroyResData(); void prepFontCacheSync(); void prepFontCacheAsync(boo::IWindow* window); - bool fontCacheReady() const { return m_fcacheReady; } + bool fontCacheReady() const { return m_fcacheReady.load(); } void resetPixelFactor(float pixelFactor); void resetTheme(const IThemeData* theme); diff --git a/specter/lib/ViewResources.cpp b/specter/lib/ViewResources.cpp index f6832d211..8e3d1c19c 100644 --- a/specter/lib/ViewResources.cpp +++ b/specter/lib/ViewResources.cpp @@ -58,33 +58,33 @@ void ViewResources::destroyResData() void ViewResources::prepFontCacheSync() { unsigned dpi = 72.f * m_pixelFactor; - if (m_fcacheInterrupt) + if (m_fcacheInterrupt.load()) return; m_mainFont = m_fcache->prepMainFont(AllCharFilter, false, 10.f, dpi); - if (m_fcacheInterrupt) + if (m_fcacheInterrupt.load()) return; m_monoFont10 = m_fcache->prepMonoFont(AllCharFilter, false, 10.f, dpi); - if (m_fcacheInterrupt) + if (m_fcacheInterrupt.load()) return; m_monoFont18 = m_fcache->prepMonoFont(AllCharFilter, false, 18.f, dpi); - if (m_fcacheInterrupt) + if (m_fcacheInterrupt.load()) return; m_heading14 = m_fcache->prepMainFont(LatinAndJapaneseCharFilter, false, 14.f, dpi); - if (m_fcacheInterrupt) + if (m_fcacheInterrupt.load()) return; m_heading18 = m_fcache->prepMainFont(LatinAndJapaneseCharFilter, false, 18.f, dpi); - if (m_fcacheInterrupt) + if (m_fcacheInterrupt.load()) return; m_titleFont = m_fcache->prepMainFont(LatinCharFilter, false, 36.f, dpi); - if (m_fcacheInterrupt) + if (m_fcacheInterrupt.load()) return; m_fcache->closeBuiltinFonts(); - m_fcacheReady = true; + m_fcacheReady.store(true); } void ViewResources::prepFontCacheAsync(boo::IWindow* window) { - m_fcacheReady = false; + m_fcacheReady.store(false); m_fcacheThread = std::thread([this]() { prepFontCacheSync(); }); }