Very strange question (Bug or Compiler?)

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Very strange question (Bug or Compiler?)

Postby Auradrummer » Wed Sep 02, 2009 2:16 pm

Hello guys,

Now I'm with a really strange question.
This is the whole code of the callback. Let's me say that everything is fine, no problem at all.

Pay attention to
Code: Select all
dVector omega.

Can you believe that if I DECLARE it my airlift car disappears?
Yes, that's right, I don't make anything with it, if I declare, my airlift disappears.

But, I found a even strange solution:
Declare it after the line
Code: Select all
nWorld = NewtonBodyGetWorld (body);


Someone can explain me that? Is a Newton bug or a compiler bug?
I'm using the old Dev-C++ .

Code: Select all
void applyGenericForce (const NewtonBody* body, dFloat timestep, int thread)
{
   dFloat mass;
   dFloat Ixx;
   dFloat Iyy;
   dFloat Izz;
   
   NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
   dVector force (0.0f, mass * GRAVITY, 0.0f);
   
    // Calculate lifter
    NewtonWorld * nWorld;   
    dFloat liftForce;
    dFloat liftHeight;
    dFloat normal;
    int faceHit;
    dVector shipPosit;
    dVector shipDownward;
    dVector torque;
    dVector omega; //<<<<<<<<<-----------------------------------------------------------
    dMatrix bodyMatrix;
    NewtonCollision * shipCol;
    RayCastInfo info (body);
    nWorld = NewtonBodyGetWorld (body);

    if (mass == 1500.0f && ship.lifter == true) // Isso significa que é a nave
    {
       NewtonBodyGetMatrix (body, &bodyMatrix[0][0]);
       shipCol = NewtonBodyGetCollision (body);

       // ship lifter
       shipPosit =  bodyMatrix.m_posit + dVector(0,1.0,0);
       shipDownward = bodyMatrix.TransformVector (dVector (0,-1,0));
       NewtonWorldRayCast (nWorld, &shipPosit[0], &shipDownward[0], RayCastInfo::RayCast, &info, NULL);
       liftHeight = info.parametro;
       liftForce = ship.liftPower * (1/liftHeight + 0.1);
       
       // ship thruster
       dVector thrust (0.0f, 0.0f, 1.0f);
       thrust = thrust.Scale(ship.thruster);
       thrust = bodyMatrix.TransformVector(thrust);
       force.m_x = thrust.m_x;
       force.m_z = thrust.m_z;
       force.m_y = force.m_y + liftForce;
       
       // ship steering
       dVector steer (0.0f, 1.0f, 0.0f);
       steer = steer.Scale(ship.steer);
       steer = bodyMatrix.TransformVector(steer);
       torque = steer;
    }

    NewtonBodySetForce (body, &force.m_x);
    NewtonBodySetTorque (body, &torque.m_x);
}
Developing a racing game.
Auradrummer
 
Posts: 132
Joined: Sat May 17, 2008 9:17 am

Re: Very strange question (Bug or Compiler?)

Postby martinsm » Wed Sep 02, 2009 2:31 pm

I would suggest that something is corrupting your stack.
What is RayCastInfo ? What is RayCastInfo::RayCast doing? maybe it is accessing memory where it should not?
Also pay attention to your compilers warnings, if it produces them - maybe there it tells something useful.
martinsm
 
Posts: 86
Joined: Mon Dec 19, 2005 3:15 pm
Location: Latvia

Re: Very strange question (Bug or Compiler?)

Postby Auradrummer » Wed Sep 02, 2009 4:25 pm

Great Martin,

No warnings.
RayCastInfo is a structure to hold the Ray Cast information. This code is made based in David Gravel's Ray Cast Car.
But, if was some problem with it, why the declaration works som lines below? This really cannot fit in my mind ...
Developing a racing game.
Auradrummer
 
Posts: 132
Joined: Sat May 17, 2008 9:17 am

Re: Very strange question (Bug or Compiler?)

Postby Dave Gravel » Wed Sep 02, 2009 5:07 pm

This can happen when you have a bad pointer or exemple a vector or matrix badly initialized somewhere.
Maybe liftPower or parametro or a other in coming from a other place.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Very strange question (Bug or Compiler?)

Postby martinsm » Thu Sep 03, 2009 4:05 am

Auradrummer wrote:But, if was some problem with it, why the declaration works som lines below? This really cannot fit in my mind ...

Well, maybe because this structure or RayCastInfo::RayCast method corrupts stack. If you put some declaration of variable, even if you don't use it, then stack gets corrupted in different way, and that's why it "works".
martinsm
 
Posts: 86
Joined: Mon Dec 19, 2005 3:15 pm
Location: Latvia

Re: Very strange question (Bug or Compiler?)

Postby Auradrummer » Thu Sep 03, 2009 8:18 am

Hum .... I'll check what both of you said ... make sense ...
Developing a racing game.
Auradrummer
 
Posts: 132
Joined: Sat May 17, 2008 9:17 am

Re: Very strange question (Bug or Compiler?)

Postby Dave Gravel » Thu Sep 03, 2009 12:00 pm

When I say badly initialized I try to say exemple:
If you use a vector but this vector don't have value set at all.
Or exemple you use a position vector and it don't finish by 1 in w.
Same about matrix.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 40 guests