I'm using box2d in my application. It has a class b2Body. It has a property void *userData and methods for it's accessing. In other words: we can store there some additional info about physic body. I want to store there some class object:
MyClass *obj = new MyClass();
b2Body body;
body.SetUserData(obj);
Now I have to get user data inside python! I wrote a function-wrapper which returns the extracted pointer:
MyClass *GetBodyUserData(b2Body &body)
{
void *userData = body.GetUserData();
if (userData) return (MyClass*)userData;
std::cout << "Fail.";
return nullptr;
}
Now, when I call GetBodyUserData in python I have an empty or 'dead' object :(.
I tried to store smart pointer insted of pure one but It's not allowed by SetUserData interface.
Any ideas?
upd Exporting to python:
bp::def("GetBodyUserData", &GetBodyUserData, boost::python::return_value_policy <boost::python::reference_existing_object>())