Funny business with compound collisions

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Funny business with compound collisions

Postby hpesoj » Fri Sep 25, 2009 9:25 am

Using Newton 2.09, the code below produces some odd results. Firstly, the compound collision shape is destroyed (or at least the destruction callback is called) before the body is destroyed. Secondly, when the body is destroyed the collision destruction callback is called with an erroneous collision pointer. I suspect something is amiss :).

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

void collisionDestructorCallback(const NewtonCollision* collision)
{
    std::cout << "destroy: " << collision << std::endl;
}

int main(void)
{
    NewtonWorld* world = NewtonCreate(0, 0);
    NewtonSetCollisionDestructor(world, collisionDestructorCallback);

    NewtonCollision* box = NewtonCreateBox(world, 1.0f, 1.0f, 1.0f, 0, 0);
    std::cout << "box: " << box << std::endl;
    NewtonCollision* compound = NewtonCreateCompoundCollision(world, 1, &box, 0);
    std::cout << "compound: " << compound << std::endl;

    NewtonBody* body = NewtonCreateBody(world, compound);

    std::cout << "Releasing compound..." << std::endl;
    NewtonReleaseCollision(world, compound);

    std::cout << "Releasing box..." << std::endl;
    NewtonReleaseCollision(world, box);

    std::cout << "Destroying body..." << std::endl;
    NewtonDestroyBody(world, body);

    NewtonDestroy(world);
}
hpesoj
 
Posts: 90
Joined: Sun Jan 09, 2005 4:36 pm
Location: Cambridge/Bristol, UK

Re: Funny business with compound collisions

Postby Julio Jerez » Fri Sep 25, 2009 11:29 am

I run it and it is correct, this is the output

box: 028FEEE0
compound: 02AD00A0
Releasing compound...
destroy: 02AD00A0

Releasing box...
Destroying body...
destroy: 02AD0160
destroy: 028FEEE0

it destroy the Cpunpount because Compound are not shared, when you attack a compound collison to a Body, teh Boidy Take a Copy of of that collision, It does tah for all no share shapes.
if it was allow to shared it teh it will malfuntion if you assign a compound to more than one body.

when you destroy the Body, the body release its compound and then compound release all the children and teh get destroyed.
The erroneos collision pointer is the Collision Shape Newton Generate from the Compound you passed in creations of the body.

I think is alright, does it cause preoblems for you?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Funny business with compound collisions

Postby hpesoj » Fri Sep 25, 2009 5:52 pm

I didn't realise this was the way compound collisions worked. The wiki would lead you to believe otherwise:

Note for Newton 1.53:

* compound collisions are instance objects that can not be shared among other rigid bodies

(In Newton 2.0, this is no longer an issue - compound collisions may be reused/shared by multiple rigid bodies just like any other collision object)


It isn't a huge problem, my program keeps track of collision shapes I have created and when the destructor callback is called it indexes into a lookup table to find and delete the associated user data. I was unaware that Newton was creating a collision shape internally, and so my assert was triggered when the unknown collision pointer was passed to the callback.
hpesoj
 
Posts: 90
Joined: Sun Jan 09, 2005 4:36 pm
Location: Cambridge/Bristol, UK

Re: Funny business with compound collisions

Postby Julio Jerez » Fri Sep 25, 2009 6:22 pm

that was in 1.53
But lot of people were having problem with compound collision trying to re-use them.
most people found hard to make muticompound collision so I chnage teh for 2.0 by making a copy.


Keeping Track of the collision is good for leack traking but in production code you do not really need it, It do e no harm.

Youc could trackl teh collision that in in eh Body, not the one you pass in,

soemthong like
if (collision == NewtonBodyGetCollsion()){
track (collision)
} else {
track (NewtonBodyGetCollsion())
}

or you could use the GetInfo and check the Ref Counters.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Funny business with compound collisions

Postby JernejL » Sat Sep 26, 2009 1:18 pm

Julio Jerez wrote:that was in 1.53
But lot of people were having problem with compound collision trying to re-use them.
most people found hard to make muticompound collision so I chnage teh for 2.0 by making a copy.


Interesting, i didn't know that each time i do this i get a new copy of compound, i use this a lot in my spaceships game, will be good to know when i start working on cleanup routines.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 5 guests

cron