ConvexCollisionCalculateVolume after ReleaseCollision

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

ConvexCollisionCalculateVolume after ReleaseCollision

Postby ledahut » Thu Jul 29, 2010 9:49 am

I would like to know if calling NewtonConvexCollisionCalculateVolume or NewtonConvexCollisionCalculateInertialMatrix with a pointer of Newton Collision, after this collision was released, could crash. Because for the moment it didn't.

Ex:
[FCollision=Pointer]

FCollision=NewtonCreateBox(world, 1, 1, 1, 0, nil);
NewtonBodySetCollision(FNewtonBody, FCollision);
NewtonReleaseCollision(world, FCollision);

FVolume = NewtonConvexCollisionCalculateVolume(FCollision);
NewtonConvexCollisionCalculateInertialMatrix(FCollision, @inertia,@origin);
...
Or should I release FCollision after volume and inertial calculs?
ledahut
 
Posts: 98
Joined: Mon Jun 21, 2010 8:03 am
Location: France

Re: ConvexCollisionCalculateVolume after ReleaseCollision

Postby Julio Jerez » Thu Jul 29, 2010 12:25 pm

Code: Select all
FCollision=NewtonCreateBox(world, 1, 1, 1, 0, nil);   // ref = 2 (1 for the world cache one for create
NewtonBodySetCollision(FNewtonBody, FCollision);    // ref = 3 (body get one ref)
NewtonReleaseCollision(world, FCollision);               // ref = 2 (you create call)

FVolume = NewtonConvexCollisionCalculateVolume(FCollision);  // fine colliosn is alive

Newton DestoyBody(body)  // Ref = 0 collsion destroyed
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: ConvexCollisionCalculateVolume after ReleaseCollision

Postby JernejL » Thu Jul 29, 2010 12:41 pm

NewtonBodySetCollision(FNewtonBody, FCollision);

That is still keeping reference counter up.. until you destroy the body it's fine.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: ConvexCollisionCalculateVolume after ReleaseCollision

Postby ledahut » Wed Aug 25, 2010 9:54 am

Calling calculateXXX after ReleaseCollision of a compound crash.

Code: Select all
1/Create Null collision
    FCollision := NewtonCreateNull(Manager.NewtonWorld);

2/Create Body with Null collision an release it
    FNewtonBody := NewtonCreateBody(Manager.NewtonWorld, FCollision);
    NewtonReleaseCollision(Manager.NewtonWorld, FCollision);

3/Create CompoundCollision
    FCollision := NewtonCreateCompoundCollision(Manager.NewtonWorld,
      Length(FCollisionArray), FCollisionArray, 0); //Of course my application release  each Collision in FCollisionArray after that

4/Set it to my null body
NewtonBodySetCollision(FNewtonBody, FCollision);
NewtonReleaseCollision(Manager.NewtonWorld, FCollision); <-- if I comment this line for compound, it calculateXXX work

5/Calculate
// FCollision:=  NewtonBodyGetCollision(FNewtonBody); <-- Or I can uncomment this line
    FVolume := NewtonConvexCollisionCalculateVolume(FCollision);
    NewtonConvexCollisionCalculateInertialMatrix(FCollision, @inertia, @origin);


(I need to check reference count).
ledahut
 
Posts: 98
Joined: Mon Jun 21, 2010 8:03 am
Location: France

Re: ConvexCollisionCalculateVolume after ReleaseCollision

Postby Julio Jerez » Wed Aug 25, 2010 10:02 am

Compound collision are no cached.
if that was teh last ref the teh object is destroyed

you can call GetInfo to see if teh Ref count is larger than 1 before relasing the shape
if it is 2 or lower it mean it will be destroyed if it is a cached mesh.
Julio Jerez
Moderator
Moderator
 
Posts: 12452
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: ConvexCollisionCalculateVolume after ReleaseCollision

Postby ledahut » Wed Aug 25, 2010 10:19 am

Thank you I have fixed that.

For others I explain with your exemple:

Code: Select all
FCollision=NewtonCreateCompoundCollision(blablabla); // ref = 1
NewtonBodySetCollision(FNewtonBody, FCollision);    // ref = 1 (body don't get one ref because Compound is not 'cached')
NewtonReleaseCollision(world, FCollision);               // ref = 0

FVolume = NewtonConvexCollisionCalculateVolume(FCollision);  // crash collision is dead
ledahut
 
Posts: 98
Joined: Mon Jun 21, 2010 8:03 am
Location: France


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 205 guests