diff --git a/libluna/include/luna/SharedPtr.h b/libluna/include/luna/SharedPtr.h index a369e75c..2442e6fe 100644 --- a/libluna/include/luna/SharedPtr.h +++ b/libluna/include/luna/SharedPtr.h @@ -23,7 +23,7 @@ struct Shareable return m_ref_count == 0; } - Atomic m_ref_count { 1 }; + Atomic m_ref_count { 0 }; }; template class SharedPtr @@ -36,6 +36,7 @@ template class SharedPtr SharedPtr(T* ptr) : m_ptr(ptr) { + if (m_ptr) shareable()->ref(); } SharedPtr(const SharedPtr& other) : m_ptr(other.m_ptr) @@ -50,7 +51,6 @@ template class SharedPtr template operator SharedPtr() { - if (m_ptr) shareable()->ref(); return { (Tp*)m_ptr }; }