GLBasic forum

Main forum => GLBasic - en => Topic started by: djtoon on 2010-Sep-19

Title: box 2d modification help
Post by: djtoon on 2010-Sep-19
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:
Title: Re: box 2d modification help
Post by: MrTAToad on 2010-Sep-19
You could try :

Code (glbasic) Select

def.userData=art_Str.c_str();
Title: Re: box 2d modification help
Post by: Kitty Hello on 2010-Sep-20
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.