box 2d modification help

Previous topic - Next topic

djtoon

hi im doing alitle mod on the box2d source and im in a little problem:
im trying to add userdata to the def
im doing this:



FUNCTION b_CreateBox1: mass, friction, restitution, x, y, w, h ,art$
   INLINE
   

   b2BodyDef def;
   def.position.Set(x,y);
   

   char *ss=art_Str;
   doit(art_Str);
   def.userData=ss;




   b2Body* pBody = bWorld->CreateBody( &def );

   b2PolygonDef poly;
      if(mass>0.0) poly.density = mass;
      poly.friction = friction;
      poly.restitution = restitution;
      poly.SetAsBox(w*.5, h*.5);
      pBody->CreateShape( &poly);
      if(mass>0.0) pBody->SetMassFromShapes();

   return b_NewObject(pBody, bBody);
   ENDINLINE
ENDFUNCTION


the art$ is a string

im trying to get it out when the object contat but im getting a weird varlues

anyone has any input?
:doubt:

MrTAToad

You could try :

Code (glbasic) Select

def.userData=art_Str.c_str();

Kitty Hello

baaaad! You store a pointer, but the memory it pointed to might change!
You can't do that. You can keep a global string list and store the index here -that's all.