Stuck in loop

Discuss any Chipmunk bugs here.
Post Reply
pepeek
Posts: 5
Joined: Tue Apr 17, 2012 5:29 am
Contact:

Stuck in loop

Post by pepeek »

Hello,

I'm compiling for MAC using Cocos2d project and program runs fine under DEBUG but gets stuck in the loop bellow under RELEASE settings.

This is the loop:

Code: Select all

void
cpSpaceHashQuery(cpSpaceHash *hash, void *obj, cpBB bb, cpSpaceHashQueryFunc func, void *data)
{
        ....
	for(int i=l; i<=r; i++){
		for(int j=b; j<=t; j++){
			query(hash, &table[hash_func(i,j,n)], obj, func, data);
		}
	}
        ....
}
The hash_func gets called over and over.

I've tried the compile RELEASE with no optimalizations but that did not help. Other then the optimalization settings the two setups are almost the same :-(

Any clue what to try to find the problem?

The README file shows last version as such:
CHANGES SINCE 5.0.0:
...

Appreciate your help!
--Josef
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Stuck in loop

Post by slembcke »

Usually when that happens it's because the 'bb' parameter is huge or infinite so the for loops take a long time to complete. Look at it in the debugger. Assuming you didn't make your object really huge, the body that shape is attached to probably has a position of NaN or infinity because there is a divide by zero error somewhere in your code.

Also, Assuming that you are running Chipmunk 5.1.0, that version is over 2 years old. You should update, there have been a number of features added that will help catch errors like that and it's a lot faster overall.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
pepeek
Posts: 5
Joined: Tue Apr 17, 2012 5:29 am
Contact:

Re: Stuck in loop

Post by pepeek »

Hi slembcke, thanks for your good hints.

The bb param is indeed infinite. It is a static body which I'm trying to create. This code has been working for years on iPad and now it gets stuck if I run it under RELEASE on MAC.

This is the static body "cushion" which I'm trying to create. It gets stuck only for the top part. The other bottom,left and right passes always fine (when I change the order).

Code: Select all

    // bottom
    shape = cpSegmentShapeNew(staticBody, ccp(0.0f,0.0f), ccp(1024.0f,0.0f), 0.0f);
    shape->e = 1.0f; shape->u = 1.0f;
    cpSpaceAddStaticShape(space, shape);
    
    // top
    shape = cpSegmentShapeNew(staticBody, ccp(0.0f,700.0f), ccp(1024.0f,700.0f), 0.0f);
    shape->e = 1.0f; shape->u = 1.0f;
    // <X><Pp><PROD><BUG> hangs here
    cpSpaceAddStaticShape(space, shape);
    
    // left
    shape = cpSegmentShapeNew(staticBody, ccp(0,0), ccp(0,wins.height), 0.0f);
    shape->e = 1.0f; shape->u = 1.0f;
    cpSpaceAddStaticShape(space, shape);
    
    // right
    shape = cpSegmentShapeNew(staticBody, ccp(wins.width,0), ccp(wins.width,wins.height), 0.0f);
    shape->e = 1.0f; shape->u = 1.0f;
    cpSpaceAddStaticShape(space, shape);
To make it complete, this is how I initiate the body prior to the above:

Code: Select all

    cpBody *staticBody = cpBodyNew(INFINITY, INFINITY);
    space = cpSpaceNew();
    cpSpaceResizeStaticHash(space, 400.0f, 40);
    cpSpaceResizeActiveHash(space, 100, 600);    
    space->gravity = ccp(0, 0);
    space->elasticIterations = space->iterations;
Thanks again for your help!
--Josef
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Stuck in loop

Post by slembcke »

No idea what is wrong with that code. I suspect something goofy with conflicting types for cpFloat depending on where you are in the program, but that is just a wild guess. I'd suggest trying to step through the code, but that's not going to be useful if it only occurs in when compiled as release.

I know there was a compiler bug in Clang 2.1 that broke Chipmunk 6, and I've heard there are issues with 3.1 (though I haven't verified it's a compiler bug). What version are you using?

Either way, I'd strongly suggest upgrading to the latest version of Chipmunk. It's hard to provide support for a version that that I haven't personally used in over 2 years.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
pepeek
Posts: 5
Joined: Tue Apr 17, 2012 5:29 am
Contact:

Re: Stuck in loop

Post by pepeek »

I'm on xCode 4.3.2, compiler is Apple LLVM 3.1 (both DEBUG and RELEASE).
I'll upgrade the latest code and hope for better results. This is definitely something goofy as you said.
Thanks for your time!
--Josef
pepeek
Posts: 5
Joined: Tue Apr 17, 2012 5:29 am
Contact:

Re: Stuck in loop

Post by pepeek »

I could not upgrade because my Chipmunk is shipped with Cocos2d and it is a bit hassle for me to upgrade. Thus I've done some tests and found out that the problem is caused by LLVM 3.1 optimalization level.

The results are:
  • Up to -O1 (fast) it works fine
  • -O2.. -O3: does not get stuck in the loop, but the static elements don't work - behave as there are none
  • -Os (fastest smallest): stuck in the loop
For now my solution is simple. -O1 settings for RELEASE for Chipmunk code.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Stuck in loop

Post by slembcke »

Ugh. I've heard a lot of bad things about the Clang 3.1 compiler having bugs in it. (This is the 4th issue that sounds compiler bug related in 3 weeks) I haven't upgraded, and the more bad things I hear about Xcode 4.3, the more I don't want to. It sounds like I'm going to have to for no reason other than to make workarounds for compiler bugs. Woo! :-\


Dear Apple.

Please test your F*(*&ing software instead of continually releasing beta quality developer tools.

Sincerely, Developers.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
pepeek
Posts: 5
Joined: Tue Apr 17, 2012 5:29 am
Contact:

Re: Stuck in loop

Post by pepeek »

Well, you've said it all and said it well. Not much to add to it. Wishing good luck and loads of patience to all of us --Josef
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests