From 2665f55b9a15939cac302dd7537b1acf99a3d9a4 Mon Sep 17 00:00:00 2001 From: GagaLP Date: Thu, 23 Jul 2026 18:30:20 +0200 Subject: [PATCH] Mark instance in cgf_diagnostics::teardown() unavailable instead of resetting it --- include/cgf_diagnostics.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/cgf_diagnostics.h b/include/cgf_diagnostics.h index fb9b59f16..3d952892e 100644 --- a/include/cgf_diagnostics.h +++ b/include/cgf_diagnostics.h @@ -12,16 +12,22 @@ namespace celerity::detail { class cgf_diagnostics { public: static void make_available() { - assert(m_instance == nullptr); + assert(!m_is_available); m_instance = std::unique_ptr(new cgf_diagnostics()); + m_is_available = true; } - static bool is_available() { return m_instance != nullptr; } + static bool is_available() { return m_instance != nullptr && m_is_available; } - static void teardown() { m_instance.reset(); } + static void teardown() { + // We don't want to reset the instance, because that would cause destruction order issues. + // Instead, we just mark this instance as unavailable. + // m_instance is handled by the unique_ptr anyway, so it will be safely destroyed. + m_is_available = false; + } static cgf_diagnostics& get_instance() { - assert(m_instance != nullptr); + assert(m_instance != nullptr && m_is_available); return *m_instance; } @@ -64,6 +70,7 @@ class cgf_diagnostics { private: inline static thread_local std::unique_ptr m_instance; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + inline static thread_local bool m_is_available; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) bool m_is_checking = false; std::optional m_expected_target = std::nullopt;