diff --git a/rpcs3/util/fixed_typemap.hpp b/rpcs3/util/fixed_typemap.hpp index 8fef2af203..896d8ae779 100644 --- a/rpcs3/util/fixed_typemap.hpp +++ b/rpcs3/util/fixed_typemap.hpp @@ -168,15 +168,15 @@ namespace stx mutable uchar m_data[Size ? Size : 1]; }; + // Indicates whether object is created at given index + std::array m_init{}; + // Creation order for each object (used to reverse destruction order) void** m_order = nullptr; // Helper for destroying in reverse order const typeinfo** m_info = nullptr; - // Indicates whether object is created at given index - bool* m_init = nullptr; - public: manual_typemap() noexcept = default; @@ -186,19 +186,19 @@ namespace stx ~manual_typemap() { - ensure(!m_init); + ensure(!m_info); } void reset() { - if (m_init) + if (is_init()) { clear(); } m_order = new void*[stx::typelist().count() + 1]; m_info = new const typeinfo*[stx::typelist().count() + 1]; - m_init = new bool[stx::typelist().count()]{}; + ensure(m_init.size() > stx::typelist().count()); if constexpr (Size == 0) { @@ -269,7 +269,7 @@ namespace stx void clear() { - if (!m_init) + if (!is_init()) { return; } @@ -295,7 +295,6 @@ namespace stx // Pointers should be restored to their positions m_info--; m_order--; - delete[] m_init; delete[] m_info; delete[] m_order; @@ -311,7 +310,7 @@ namespace stx } } - m_init = nullptr; + m_init.fill(false); m_info = nullptr; m_order = nullptr; @@ -323,7 +322,7 @@ namespace stx void save(utils::serial& ar) { - if (!m_init) + if (!is_init()) { return; } @@ -412,6 +411,11 @@ namespace stx return m_init[stx::typeindex>()]; } + bool is_init() const noexcept + { + return m_info != nullptr; + } + // Obtain object pointer (may be uninitialized memory) template T& get() const noexcept