• 10
• 9
• 13
• 10
• 18

# Access Violation using shared_ptr's...

This topic is 2028 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

 class CDemo : public D3DApp { vector<shared_ptr<CObject>> m_pRenderObjects; }; CDemo::CDemo { shared_ptr<CObject> wh(new CWarehouse()); m_pRenderObjects.push_back(wh); } CDemo::~CDemo { // Access Violation here } 
Thanks
Jack

##### Share on other sites
There is nothing wrong with the code given (except it would not compile like that). The error could be in any number of places, as usual for C++ programs (duplicate delete, trashed heap by writing over owned memory, etc., etc.).

One thing that sticks out is the naming of "m_pRenderObjects" and "D3DApp". Is it possible the D3DApp releases the DirectX interfaces before entering its destructor? In that case, deleting anything that still believes it holds DirectX interfaces that needs releasing (like a render object) will likely crash.
However, if that were the case I would expect the stacktrace of the crash being much closer to the source. You are debugging a debug build, are you not? Edited by BitMaster