shared_ptr Assertion px != 0 failed

you might want to make sure that you

always use a named smart pointer variable to hold the result of new

like it is recommended here: boost::shared_ptr - Best Practices

Regards, Jonny


There should be no problem with using boost::shared_ptr as long as you initialize your shared pointers correctly and use the same memory management context for all your shared object libraries.

In your case you are trying to use an uninitialized shared pointer.

boost::shared_ptr<Obj> obj;
obj->Something(); // assertion failed

boost::shared_ptr<Obj> obj(new Obj);
obj->Something(); // ok

I would advise to initialize them right on declaration whenever possible. Exception handling can create a lot of "invisible" paths for the code to run and it might be quite difficult to identify the non initialized shared pointers.

PS: There are other issues if you load/unload modules where shared_ptr are in use leading to chaos. This is very hard to solve but in this case you would have a non zero pointer. This is not what is happening to you right now.

PPS: The pattern used is called RAII (Resource Acquisition Is Initialization)