when loading in my RUBE scene I am trying to do some extra processing afterwards by creating some specific game objects and attaching them to the appropriate b2Body objects via body->SetUserData(myObj);
When running a world physics step the app crashes with a segmentation fault. This only happens if I try to attach to the body. If attach my user data to one of its fixtures it runs ok.
Referring to the sample loaders, I am doing this in the afterLoadProcessing() method
e.g)
afterLoadProcessing(b2dJson* json) {
// this will result in a crash when world->Step() is called first time
b2Body* body json->getBodyByName("mybody");
body->SetUserData(myObj);
// this works
b2Fixture* fixture json->getFixtureByName("myfixture");
fixture->SetUserData(myObj);
}
Is there something wrong with trying to attach to the body?
Whereabouts does it crash? If you call world->Step immediately after the body->SetUserData line, does it crash then? Box2D does not actually use the user data in any way, so I'm guessing you must be doing something with it yourself when you're stepping (otherwise there is no point to having it), and that is the location where the crash occurs.
thanks I assumed it was something stupid I was doing, but just wanted to verify the body userdata wasnt reserved by the scene. Definitely my problem, thanks for the reply