Assertion failed error after moving to chipmunk 5

Official forum for the Chipmunk2D Physics Library.
User avatar
Bongeh
Posts: 11
Joined: Wed Feb 03, 2010 7:25 am
Contact:

Assertion failed error after moving to chipmunk 5

Post by Bongeh »

Hi there,

I've been using chipmunk in conjunction with cocos2d for about a month now, and i decided to upgrade to v5 because of the begin and seperate collision handlers etc, from what ive used and seen, its a huge improvement! :D

i rewrote my collisionhandlers and ran my program with 1 enemy sprite, everything worked fine, collisions did as they were sposed too..

as soon as i add any more sprites into my game i get this error

Assertion failed: (value), function k_scalar, file /User/Documents/Games/platforms/libs/Chipmunk/src/include/chipmunk/constraints/util.h, line 72.

I'm not entirely sure where im going wrong, but i believe its being caused as i add more objects to the "gameSpace"?

I'll be happy to post code if you need to see it.

My enemy sprites are a subclass of CCSprite (cocos) which have an init function that sets up there cpShape/body thing.

The error happens regardless of wether i add the objects as children to my scene, so im guessing it must be happening as they are added into chipmunks space.
Last edited by Bongeh on Thu Feb 11, 2010 5:11 pm, edited 1 time in total.
User avatar
Bongeh
Posts: 11
Joined: Wed Feb 03, 2010 7:25 am
Contact:

Re: Assertion failed error after moving to chipmunk 5

Post by Bongeh »

ive found the function that seems to be causing the crash.

Code: Select all

-(void)setSpace:(cpSpace*)sp {
			
	float num = 27.5;

	// Register the chipmunk space and add player body to it.
	_space = sp;
			
	// Make chipmunk body
	// Make sprite body with 0 mass and 0 moment
	_blockBody = cpBodyNew(INFINITY, INFINITY);
	_blockBody->p = self.position;
			
	// Now make the shape and add it to the body

	cpVect blockVerts[] = {
		cpv(-50, -num),
		cpv(-50, num),
		cpv(50, num),
		cpv(50, -num),
	};
	
	_blockShape = cpPolyShapeNew(_blockBody, 4, blockVerts, cpvzero);
	_blockShape->collision_type = 2;	
	_blockShape->data = self;
		
	cpSpaceAddShape(_space, _blockShape);
	
}
this gets called on my first object, and works fine, when i make a second object and call this func on that one, it causes the crash...

i dont understand this because the function is the same for both instances of the object, all i can think is that perhaps in chipmunk 5 you need to do something so it knows they two object's shapes are different or something?
User avatar
Bongeh
Posts: 11
Joined: Wed Feb 03, 2010 7:25 am
Contact:

Re: Assertion failed error after moving to chipmunk 5

Post by Bongeh »

i checked out chipmunk to the latest revision and am now getting this.

Code: Select all

Aborting due to Chipmunk error: Unsolvable collision or constraint.
	Failed condition: value != 0.0
	Source:/Users/Documents/Games/platforms/libs/Chipmunk/src/constraints/util.h:70
which is the same bug, yeah?
Last edited by Bongeh on Thu Feb 11, 2010 5:12 pm, edited 1 time in total.
User avatar
slembcke
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Assertion failed error after moving to chipmunk 5

Post by slembcke »

Yeah, I went back and redid all the assertions to print out more descriptive errors a day or two ago.

You are probably allowing two objects of infinite mass to collide. Try inspecting the two bodies in the k_scalar function using the debugger when it crashes.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
Bongeh
Posts: 11
Joined: Wed Feb 03, 2010 7:25 am
Contact:

Re: Assertion failed error after moving to chipmunk 5

Post by Bongeh »

thank you for your reply, if i have not set a collision handler for objects of the same collision type to touch each other, does it not just ignore them?
User avatar
Bongeh
Posts: 11
Joined: Wed Feb 03, 2010 7:25 am
Contact:

Re: Assertion failed error after moving to chipmunk 5

Post by Bongeh »

all of my objects have infinity mass.

my player, my enemies, they did in chipmunk 4.. im not using chipmunk to simulate the reactions of the collisions, just to detect them.

i thought this was the correct way to do it if i didnt want chipmunk to use forces on them.
User avatar
Bongeh
Posts: 11
Joined: Wed Feb 03, 2010 7:25 am
Contact:

Re: Assertion failed error after moving to chipmunk 5

Post by Bongeh »

sorry for the triple post!

You were entirely correct! :D

it was that two of my enemies spawned on the same spot.

I wish for some of my enemies to be able to pass through each other, and for me not to have this crash. What do i need to do in order to stop this from happening? give them a set mass instead of INFINITY?
User avatar
slembcke
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Assertion failed error after moving to chipmunk 5

Post by slembcke »

So you are using Chipmunks collision detection by setting the positions of the sprites at every frame? That assertion happens from within the impulse solver, and if allowed to continue would result in the velocity of the objects getting set to NaN. This would have happened in Chipmunk 4 as well, just without the assertion. So I assume you must be overwriting the positions or something.

If you don't need the collision response that Chipmunk calculates, you should set the space's iterations and elastic iterations to 0 to disable it. The impulse solver tends to be the most expensive part of Chipmunk anyway.

Lastly, to disable the assertions altogether, you need to compile with -DNDEBUG. Add it to the "other C flags" property in the XCode target's build settings. You should be doing this at least for release as some of the assertions can be expensive.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
Bongeh
Posts: 11
Joined: Wed Feb 03, 2010 7:25 am
Contact:

Re: Assertion failed error after moving to chipmunk 5

Post by Bongeh »

thank you very much slembcke, yes, for this project i am just using chipmunk as an easy way to detect accurate collisions on non ordinary shapes, an L shape etc...

I have a scheduler that cycles through my sprites and updates there positions manually yes.

Thanks again
User avatar
slembcke
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Assertion failed error after moving to chipmunk 5

Post by slembcke »

The issue that the assertion is trying to prevent is bodies basically disappearing when an unsolvable collision happens. It would have been happening to you before had you not overwritten the positions of the objects every time before drawing them. So you just never knew it.

What you should be doing is returning false from all of your collision handler preSolve() callbacks. That way the collisions will never be added to the solver. Then disable the solver entirely by setting iterations and elastic iterations to 0. This way you've disabled queuing the collisions to the solver system as well as attempting to solve them. This make the game run measurably faster. Make sure to disable the assertions when compiling for release/distribution as well.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest