NewtonInvalidateCache resets object masses to 0? (w/ demo)

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonInvalidateCache resets object masses to 0? (w/ demo)

Postby agi_shi » Sun Jul 19, 2009 11:16 am

Code: Select all
NewtonInvalidateCache(_world);


Whenever I start my editor's simulation, I make the above call (to make sure everything (re)starts clean - or is it not necessary?)

When there no 0 mass objects (other than tree collisions, which are automatically 0 mass), everything works fine.

However, if there is a 0 mass (non-tree collision) object, such as a box or a sphere, or perhaps a convex hull, etc (or a convex hull modifier), then all of the objects in the scene seem to get 0 mass (and thus become immobile). If, as the simulation is running (but no objects are moving, as mentioned), I select one of my objects and reset the mass (it is reported correctly, but I reset the mass to the same number anyway), then that object starts to move once again.

This isn't the latest 2.03 version, but rather 1 or 2 versions behind that (on Windows). I haven't had time to upgrade to 2.03 just yet, so perhaps this bug is fixed :mrgreen:
Last edited by agi_shi on Sun Jul 19, 2009 2:05 pm, edited 1 time in total.
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: NewtonInvalidateCache resets object masses to 0?

Postby Julio Jerez » Sun Jul 19, 2009 1:42 pm

agi_shi wrote:However, if there is a 0 mass (non-tree collision) object, such as a box or a sphere, or perhaps a convex hull, etc (or a convex hull modifier), then all of the objects in the scene seem to get 0 mass (and thus become immobile).

Oh really, no nothong liek that had being fixed, I will check it out.
do not bother going to 2.03 because 2.04 is almost ready and it have few changes. you can skip 2.03
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonInvalidateCache resets object masses to 0?

Postby agi_shi » Sun Jul 19, 2009 1:47 pm

Julio Jerez wrote:
agi_shi wrote:However, if there is a 0 mass (non-tree collision) object, such as a box or a sphere, or perhaps a convex hull, etc (or a convex hull modifier), then all of the objects in the scene seem to get 0 mass (and thus become immobile).

Oh really, no nothong liek that had being fixed, I will check it out.

Roger that. I'll try to code up a little demo to help with reproducing the bug for debugging.

do not bother going to 2.03 because 2.04 is almost ready and it have few changes. you can skip 2.03

Cool, I'll wait for 2.04 :mrgreen:
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: NewtonInvalidateCache resets object masses to 0?

Postby agi_shi » Sun Jul 19, 2009 2:04 pm

Shortest possible example that demonstrates the bug:

Code: Select all
#include <iostream>
#include <Newton.h>

void gravity(const NewtonBody *body, float dt, int thread)
{
    float f[] = { 0, -9.81, 0 };

    NewtonBodyAddForce(body, f);
}

int main()
{
    NewtonWorld *world = NewtonCreate(NULL, NULL);

    // just a quick collision
    NewtonCollision *col = NewtonCreateBox(world, 1, 1, 1, NULL);

    // two bodies - one static, one not
    NewtonBody *dyn = NewtonCreateBody(world, col);
    NewtonBody *stat = NewtonCreateBody(world, col);

    NewtonBodySetForceAndTorqueCallback(dyn, &gravity);
    NewtonBodySetForceAndTorqueCallback(stat, &gravity);

    NewtonBodySetMassMatrix(dyn, 1, 1, 1, 1);
    NewtonBodySetMassMatrix(stat, 0, 0, 0, 0);

    /*!
        bug: uncomment following call and the
        dynamic body will not move unless you
        make a NewtonBodySetMassMatrix() call
    */
    //NewtonInvalidateCache(world);

    float time = 0;
    while (time < 5)
    {
        const float STEP = 1.0 / 60.0;
        time += STEP;

        NewtonUpdate(world, STEP);

        float mat[16] = { 0 };

        /*
            0   1   2   3
            4   5   6   7
            8   9   10  11
            12  13  14  15
        */

        NewtonBodyGetMatrix(dyn, mat);

        std::cout << "dyn Y: " << mat[13] << "\n";

        NewtonBodyGetMatrix(stat, mat);

        std::cout << "stat Y: " << mat[13] << "\n\n";
    }

    NewtonDestroyBody(world, dyn);
    NewtonDestroyBody(world, stat);

    NewtonReleaseCollision(world, col);

    NewtonDestroy(world);
}



As long as the call is commented, dyn Y will keep going down due to gravity and stat Y will stay at 0. However, if the call is uncommented, dyn Y will also stay at 0 unless you call NewtonBodySetMassMatrix() for the body after the NewtonInvalidateCache() call.
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: NewtonInvalidateCache resets object masses to 0? (w/ demo)

Postby Julio Jerez » Sun Jul 19, 2009 7:40 pm

Oh you were correct, Th efuntion was bogus, I made an optimization tha broke the function and I did not realized it.
I am glad you posted the demo to expose the bug, it showed it right away, it would be much harder for me to find without the demo.

Any way, I fix it and now.
when I get the Linux and Mac build I will post new Beta 2.04.

Thank you.
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