I probably haven't understood something very basic here and kindly ask for help. There is a problem occurring since i switched from raw pointers to std::unique_ptr.
I have a singleton i use for debug drawing of primitive shapes. It holds unique pointers to several member objects like
...
std::unique_ptr<Program> m_shaderDebug{ nullptr };
std::unique_ptr<VertexArray3D<omath::dvec3>> m_boxArray{ nullptr };
...
I get the singleton like this as a member of another drawable object O:
orf_n::DrawPrimitives &m_drawPrimitives{ orf_n::DrawPrimitives::getInstance() };
Somewhere in O i call the setup:
m_drawPrimitives.setupDebugDrawing();
That sets the above members of the singleton like for example:
Icosphere is{ omath::dvec3{ 0.5, 0.5, 0.5 }, 2 };
m_sphereArray = std::make_unique<VertexArray3D<omath::dvec3>>( is.getVertices(), 0, true );
m_sphereIndices = std::make_unique<IndexBuffer>( is.getIndices() );
and a flag m_allSetup that setup has taken place.
Now, when i call the singleton's cleanup method that simply does
if( m_allSetup ) {
m_boxArray.reset();
m_shaderDebug.reset();
m_boxIndices.reset();
....
the program exits fine.
If i wait for the singleton's destructor to call the cleanup method, the program segfaults. The debugger tells me the pointers holdvalid objects of the respective type at that time.
I probably haven't got something basic here.
Let me know if you need more code.