DGRaycastVehicle crash

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

DGRaycastVehicle crash

Postby Relfos » Tue May 31, 2011 7:19 pm

I'm trying to implement a kart racing game, right now the only bodies I have on the scene is a treecolision mesh and a box mesh (for the kart).
However calling DGRaycastVehicleCreate makes Newton crash next time NewtonUpdate is called.
I'm using Delphi, the error that appears when crashing is not much informative, seems to be a read from adress 0000000 on the newton DLL.

Here is my code, I've compared it with the tutorials and it seems ok.
Note that even if I comment the DGRaycastVehicleSetTireTransformCallback and DGRaycastVehicleAddTire it still crashes.
If I comment DGRaycastVehicleCreate it runs fine (but of course, there is no car physics, just a normal box)

What could it be?

Code: Select all
Procedure Kart.InitPhysics;
Var
   P:Vector3D;
   origin, inertia:Vector3D;
  chassisMatrix, M:Matrix;
  I:Integer;
  Collision :PNewtonCollision;
Begin
  _Size := VectorCreate(7, 4, 12);
  Collision  := NewtonCreateBox(_World, _Size.x, _Size.y, _Size.z, 0, nil);
  // Create the rigid body
  _Body := NewtonCreateBody(_World, Collision, @MatrixIdentity);

  // Now we calculate the moment of intertia for this box. Note that a correct
  // moment of inertia is CRUCIAL for the CORRECT PHYSICAL BEHAVIOUR of a body,
  // so we use an special equation for calculating it
  P.x := CarMass * (_Size.y * _Size.y + _Size.z * _Size.z) / 12;
  P.y := CarMass * (_Size.x * _Size.x + _Size.z * _Size.z) / 12;
  P.z := CarMass * (_Size.x * _Size.x + _Size.y * _Size.y) / 12;

  // Set the bodies mass and moment of inertia
  NewtonBodySetMassMatrix(_Body, CarMass, P.x, P.y, P.z);


   // the first thing we need to do is to place the vehicle center of Mass on a stable position for a car
   NewtonConvexCollisionCalculateInertialMatrix(Collision, @inertia, @origin);

   //displace the center of mass by some value
   origin.Y := origin.Y  - 0.5 * _Size.Y * LOW_CENTER_OF_MASS_FACTOR;

   // now we Set a new center of mass for this car
   NewtonBodySetCentreOfMass(_body, @origin);

   // Next we need to set the internal coordinate system of the car geometry
   // this particular demo the car direction of motion is axis (1, 0, 0)
   // the car up direction (0, 1, 0);
   // the car lateral direction is the cross product of the front and vertical axis
   chassisMatrix := MatrixIdentity;

  // create a vehicle joint with 4 tires
   _Joint := DGRaycastVehicleCreate(4, @chassisMatrix, _Body);

   // now we will add four tires to this vehicle,
  For I:=0 To 3 Do
     DGRaycastVehicleAddTire(_Joint, @_Wheels[I], @(_Wheels[I].Center), TIRE_MASS, _Wheels[I].Radius, _Wheels[I].Width, 2.5, 0.25, 150.0, 5.0, 1);

  // Now set the position of the body's matrix
  NewtonBodyGetMatrix(_Body, @M);
  M.V[12] := _Position.x;
  M.V[13] := _Position.y;
  M.V[14] := _Position.z;
  NewtonBodySetMatrix(_Body, @M);

  // Finally set the callback in which the forces on this body will be applied
  NewtonBodySetForceAndTorqueCallBack(_Body, ForceAndTorqueCallBack);

  // we need to set a transform call back to render the tire entities
   DGRaycastVehicleSetTireTransformCallback(_Joint, TireTransformCallback);

  // Remove the collider, we don't need it anymore
  NewtonReleaseCollision(_World, Collision);

  NewtonBodySetUserData(_Body, Self);
End;
Relfos
 
Posts: 10
Joined: Tue May 31, 2011 5:31 pm

Re: DGRaycastVehicle crash

Postby Relfos » Wed Jun 01, 2011 6:57 am

It seems that someone else also has found this bug some months ago, the description is similar
viewtopic.php?f=9&t=4641&start=15#p45554
Relfos
 
Posts: 10
Joined: Tue May 31, 2011 5:31 pm

Re: DGRaycastVehicle crash

Postby ledahut » Wed Jun 01, 2011 6:57 pm

chassisMatrix, M:Matrix;

Your type 'Matrix' look strange. Newton expect array.

M.V[12] := _Position.x;

'Matrix' is an object or a record (a C structure), and I don't think array=record in memory.
That why your code can crash with get/set Newtonmatrix and dgraycastCreate.

Also the same with
origin, inertia:Vector3D;
newton expect array.

When i see 'origin.Y' or 'M.V[12]' i know that the types you use are not pure array (array [0..3] of double).
I wrote dgraycast code in delphi without crash (newton 2.30)
ledahut
 
Posts: 98
Joined: Mon Jun 21, 2010 8:03 am
Location: France

Re: DGRaycastVehicle crash

Postby Relfos » Wed Jun 01, 2011 7:06 pm

Hmm, I don't think that is the problem tough, my matrix and vectors are pascal records instead of arrays, but they are binary compatible, they work perfectly with openGL and newton (except the cars).
Could you send me source code of something using newton vehicles written in delphi?

Edit: Wait, you say, array[0..3] of double? Are you sure?
I tough vectors in newton were array[0..2] of single, can you confirm this?

Edit2: But actually, the function that crashes everything is DGRaycastVehicleCreate, and that one does not receive any vector. I'm very confused now.
Relfos
 
Posts: 10
Joined: Tue May 31, 2011 5:31 pm

Re: DGRaycastVehicle crash

Postby JernejL » Thu Jun 02, 2011 3:24 am

if you use double precision newton you need to use 64 bit floats, but i'm not sure what the car joint library uses internally.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: DGRaycastVehicle crash

Postby Julio Jerez » Thu Jun 02, 2011 8:53 am

can you post a test program so that I can check it?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 6 guests

cron