diff --git a/luna/include/luna/SharedPtr.h b/luna/include/luna/SharedPtr.h index b645a6aa..cdf02fb5 100644 --- a/luna/include/luna/SharedPtr.h +++ b/luna/include/luna/SharedPtr.h @@ -42,7 +42,7 @@ template class SharedPtr SharedPtr(const SharedPtr& other) : m_ptr(other.m_ptr), m_ref_count(other.m_ref_count) { - m_ref_count->ref(); + if (m_ref_count) m_ref_count->ref(); } SharedPtr(SharedPtr&& other) : m_ptr(other.m_ptr), m_ref_count(other.m_ref_count) @@ -51,6 +51,12 @@ template class SharedPtr other.m_ref_count = nullptr; } + template operator SharedPtr() + { + if (m_ref_count) m_ref_count->ref(); + return { (Tp*)m_ptr, m_ref_count }; + } + ~SharedPtr() { if (m_ref_count && m_ref_count->unref()) @@ -73,7 +79,7 @@ template class SharedPtr m_ptr = other.m_ptr; m_ref_count = other.m_ref_count; - m_ref_count->ref(); + if (m_ref_count) m_ref_count->ref(); return *this; }