I am trying to use Loki::SmartPtr and I
don't understand how it works :
I am using it like this :
// Gdiplus is a namespace holding objects used to draw on Windows
typedef Loki::SmartPtr<Gdiplus::GraphicsPath> GraphicsPathPtr ;
typedef std::vector<GraphicsPathPtr> GraphicsPathList;
typedef std::vector<GraphicsPathPtr>::iterator GraphicsPathListIt;
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
path = new GraphicsPath(FillMode::FillModeAlternate);
return bHandled = FALSE;
LRESULT OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
path = new GraphicsPath(FillMode::FillModeAlternate); // CRASH !!!!
When my application is launched I create a Gdiplus::GraphicsPath, then user
draw on screen and
when he releases mouse button OnLButtonUp is called.
Inside OnLButtonUp I first want to delete the pointer so path.~SmartPtr is called
that seem to delete the pointer.
However when I do path = new GraphicsPath(FillMode::FillModeAlternate); it
seems smart pointer
is still using the deallocated pointer and it crashs
I am sure I am doing something wrong but don't know what...
path = NULL seems to work ...
you shouldn't call the destructor,
path = new GraphicsPath(FillMode::FillModeAlternate)
the smartpointer will do the householding: if it holds the only reference to the pointee, it will delete it before assigning it to the new object.
path = 0 causes the same effect, but extra step is not needed.
Hum actually not sure it works fine ... because it still crash but later on.
I think smartpointer are too smart for me.
before reassigning, you could check the reference count of the smrtptr, to see if the refcount is 1 . If not, another smartpointer (one that you store in the array?) still holds a reference to the object.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.