Unhandled exception (sdk 1.53) on HeapFree

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Unhandled exception (sdk 1.53) on HeapFree

Postby greg2fs » Sun Jul 19, 2009 5:34 am

Hello, I can't find what is wrong in my program. First I had 2 programs, on for a vehicule and another for a character, and witch individualy works very good, but now I am trying to put the 2 programs together but I meet a runtime error witch doesn't seems to appen exactly at the same line in my code but approximatively in the same portion of code:

Code: Select all

///////////////////////////////////////////////////////////
   {
      NewtonCollision* collision[2];
      D3DXMATRIX location;
      D3DXMatrixIdentity(&location);
   //
      D3DXMatrixRotationYawPitchRoll(&mat0,0,0,0);
      D3DXMatrixTranslation(&mat1,0/10,2.42f/10,0/10);
      mat0*=mat1;
      collision[0] = NewtonCreateBox (nWorld, 2.23f/10,4.93f/10,0.4f/10, &mat0._11);
   //
      D3DXMatrixRotationYawPitchRoll(&mat0,0,0,0);
      D3DXMatrixTranslation(&mat1,0/10,5.31f/10,0/10);
      mat0*=mat1;
      collision[1] = NewtonCreateBox (nWorld, 7.28f/10,0.87f/10,0.92f/10, &mat0._11);
      
      NewtonCollision* collcompoud=NewtonCreateCompoundCollision(nWorld,2,collision);

      Guidon.body = NewtonCreateBody (nWorld, collcompoud);

      NewtonReleaseCollision (nWorld, collision[0]);
      NewtonReleaseCollision (nWorld, collision[1]);
      NewtonReleaseCollision (nWorld, collcompoud);
      //     *     *     *     *     *     *

      BODYUSERDATA* BUD=new BODYUSERDATA;
      BUD->Moto=this;
      BUD->notype=2;
      BUD->noclass=no;
      NewtonBodySetUserData (Guidon.body, BUD);
      NewtonBodySetTransformCallback (Guidon.body, PhysicsSetTransform);
      NewtonBodySetForceAndTorqueCallback (Guidon.body, PhysicsApplyForceAndTorque);
      V=D3DXVECTOR3(6.0f/10,4.93f/10,0.9f/10);
      mass = 5;
      Ixx = 0.7f * mass * (V.y * V.y + V.z * V.z) / 12.0f;
      Iyy = 0.7f * mass * (V.x * V.x + V.z * V.z) / 12.0f;
      Izz = 0.7f * mass * (V.x * V.x + V.y * V.y) / 12.0f;
      NewtonBodySetMassMatrix (Guidon.body, mass, Ixx, Iyy, Izz);
      NewtonBodySetMatrix (Guidon.body, &location._11);
      PhysicsSetTransform (Guidon.body, &location._11);
   }                                                                              
///////////////////////////////////////////////////////////
   {
      NewtonCollision* collision;
      D3DXMATRIX location; D3DXMatrixIdentity(&location);
   //
      D3DXMatrixRotationYawPitchRoll(&mat0,0,0,0);
      D3DXMatrixTranslation(&mat1,0/10,-2.31f/10,0/10);
      mat0*=mat1;
      collision = NewtonCreateBox (nWorld, 2.34f/10,4.48f/10,1/10, &mat0._11);
      
      Suspension.body = NewtonCreateBody (nWorld, collision);

      NewtonReleaseCollision (nWorld, collision);
      //     *     *     *     *     *     *

      BODYUSERDATA* BUD=new BODYUSERDATA;
      BUD->Moto=this;
      BUD->notype=3;
      BUD->noclass=no;
      NewtonBodySetUserData (Suspension.body, BUD);
      NewtonBodySetTransformCallback (Suspension.body, PhysicsSetTransform);
      NewtonBodySetForceAndTorqueCallback (Suspension.body, PhysicsApplyForceAndTorque);
      V=D3DXVECTOR3(2.34f/10,4.48f/10,1/10);
      mass = 5;
      Ixx = 0.7f * mass * (V.y * V.y + V.z * V.z) / 12.0f;
      Iyy = 0.7f * mass * (V.x * V.x + V.z * V.z) / 12.0f;
      Izz = 0.7f * mass * (V.x * V.x + V.y * V.y) / 12.0f;
      NewtonBodySetMassMatrix (Suspension.body, mass, Ixx, Iyy, Izz);
      NewtonBodySetMatrix (Suspension.body, &location._11);
      PhysicsSetTransform (Suspension.body, &location._11);
   }                                                                              
///////////////////////////////////////////////////////////
   {
      NewtonCollision* collision;
      D3DXMATRIX location; D3DXMatrixIdentity(&location);
   //
      D3DXMatrixRotationYawPitchRoll(&mat0,0,0,0);
      D3DXMatrixTranslation(&mat1,0,0,0);
      mat0*=mat1;
      collision = NewtonCreateChamferCylinder (nWorld, 8.59f/2/10, 0.96f/10, &mat0._11);
      
      RAvant.body = NewtonCreateBody (nWorld, collision);

      NewtonReleaseCollision (nWorld, collision);
      //     *     *     *     *     *     *

      BODYUSERDATA* BUD=new BODYUSERDATA;
      BUD->Moto=this;
      BUD->notype=4;
      BUD->noclass=no;
      NewtonBodySetUserData (RAvant.body, BUD);
      NewtonBodySetTransformCallback (RAvant.body, PhysicsSetTransform);
      NewtonBodySetForceAndTorqueCallback (RAvant.body, PhysicsApplyForceAndTorque);
      V=D3DXVECTOR3(0.96f/10,8.59f/2/10,8.59f/2/10);
      mass = 5;
      Ixx = 0.7f * mass * (V.y * V.y + V.z * V.z) / 12.0f;
      Iyy = 0.7f * mass * (V.x * V.x + V.z * V.z) / 12.0f;
      Izz = 0.7f * mass * (V.x * V.x + V.y * V.y) / 12.0f;
      NewtonBodySetMassMatrix (RAvant.body, mass, Ixx, Iyy, Izz);
      NewtonBodySetMatrix (RAvant.body, &location._11);
      PhysicsSetTransform (RAvant.body, &location._11);
   }                                                                              
///////////////////////////////////////////////////////////
   {
      NewtonCollision* collision;
      D3DXMATRIX location; D3DXMatrixIdentity(&location);
   //
      D3DXMatrixRotationYawPitchRoll(&mat0,0,0.17f,0);
      D3DXMatrixTranslation(&mat1,0/10,-0.28f/10,2.63f/10);
      mat0*=mat1;
      collision = NewtonCreateBox (nWorld, 2.21f/10,1/10,6.21f/10, &mat0._11);
      
      BrasO.body = NewtonCreateBody (nWorld, collision);

      NewtonReleaseCollision (nWorld, collision);
      //     *     *     *     *     *     *

      BODYUSERDATA* BUD=new BODYUSERDATA;
      BUD->Moto=this;
      BUD->notype=5;
      BUD->noclass=no;
      NewtonBodySetUserData (BrasO.body, BUD);
      NewtonBodySetTransformCallback (BrasO.body, PhysicsSetTransform);
      NewtonBodySetForceAndTorqueCallback (BrasO.body, PhysicsApplyForceAndTorque);
      V=D3DXVECTOR3(2.21f/10,1/10,6.21f/10);
      mass = 2;
      Ixx = 0.7f * mass * (V.y * V.y + V.z * V.z) / 12.0f;
      Iyy = 0.7f * mass * (V.x * V.x + V.z * V.z) / 12.0f;
      Izz = 0.7f * mass * (V.x * V.x + V.y * V.y) / 12.0f;
      NewtonBodySetMassMatrix (BrasO.body, mass, Ixx, Iyy, Izz);
      NewtonBodySetMatrix (BrasO.body, &location._11);
      PhysicsSetTransform (BrasO.body, &location._11);
   }                                                                              
///////////////////////////////////////////////////////////


The error:
Code: Select all
Exception non gérée à 0x7c812afb dans LandWar.exe : Exception Microsoft C++ : std::bad_alloc à l'emplacement mémoire 0x0012e36c..
(this error occurs in operator new)



Note than I use directx but it's quite the same, I didn't put all the code hopping someone of you will immediatly see a big mistake in this code in witch the error occurs.
Another thing is than I'm french then please tell me if you don't understand something I wrote, I really need help.

Thanks in advance.
Image
greg2fs
 
Posts: 32
Joined: Sat May 24, 2008 12:36 pm

Re: Unhandled exception (sdk 1.53) on HeapFree

Postby greg2fs » Sun Jul 19, 2009 6:49 am

So sorry, I found the bug, in fact the user data I used for the first program was not the same on the second one !
Image
greg2fs
 
Posts: 32
Joined: Sat May 24, 2008 12:36 pm

Re: Unhandled exception (sdk 1.53) on HeapFree

Postby Julio Jerez » Sun Jul 19, 2009 9:34 am

Glad you foun dteh bug,

but you should move to 2.0 sdk
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron