b2Body SetUserData() error

General discussion about the R.U.B.E editor
Post Reply
msm1982
Posts: 17
Joined: Tue Aug 20, 2013 4:13 pm

b2Body SetUserData() error

Post by msm1982 »

Hi,

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)

Code: Select all

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?

Thanks for the help
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: b2Body SetUserData() error

Post by iforce2d »

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.
msm1982
Posts: 17
Joined: Tue Aug 20, 2013 4:13 pm

Re: b2Body SetUserData() error

Post by msm1982 »

ugh,

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
Post Reply