co-processor offset out of range

Apprentice
Posts: 8
Joined: 2010.09
Post: #1
hi folks,

i have a strange compiling problem with xcode and iphone. my game is almost finish but now i got suddently this compiling error:

{standard input}:6108:co-processor offset out of range
gcc-4.2 failed with exit code 1

this only happens if i compile the release version for the device. the debug version and both versions for the simulator works. clean targets and recompile don't work.
strangly enough that error only happens if i add a line of code to one specific source file and only between these lines:

Code:
[_sharedDirector checkAndPutScoreToHighscore:(int)[player score]];
gameOverScreen = YES;
gameOverScreenSlideY = 320.0f;
[buttonManager activateButtonWithID:replayButton];
[buttonManager activateButtonWithID:menuButton];

so when i put a random line between this lines of code i get that error.
i do not know what causes this error. i had opened the sourcecode file to "show as assembly file" just for fun but i don't think this has caused the error.
has anybode a hint for me what could be going on? i am searching the web for over 3 hours and thats very frustrating.

greets
spuckfunkel

http://www.microsia.de - become a micromusician and create molecular tunes
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #2
That's weird. Have you tried setting the optimization level to -O0 by chance?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Seems pretty clear-cut a compiler bug... unless you have some inline assembly you're not showing us Wink The question is, what's triggering it / how can you work around it? I'd try making more & smaller functions.

You should file a bug report at http://bugreport.apple.com/
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #4
I agree, this has the stench of compiler bug all over it. Yeah, it'd be nice if you could come up with the smallest reproducible test case for it.
Quote this message in a reply
Apprentice
Posts: 8
Joined: 2010.09
Post: #5
changing the optimazian level does not make any difference. maybe it's a compiler bug but i can't reproduce it.
it seems like the methode which causes the error is fixed by it's length. that means if i put random lines of code anywhere in that methode this error occures. without new lines of code > no error.
so for example if i put five times:

Code:
NSLog(@"test");

the error occures. four times the "NSlog" and there is no error. and it does not matter in which position of the methode i put the new lines.
so it seems like the methode now has a fixed length of code. could a be that showing the sourcefile in assembly code (i only watched the assembly code for a while didn't make any changes) has anything to do with that? because i only looked at the assembly code of this one sourcefile which now causes the error.

http://www.microsia.de - become a micromusician and create molecular tunes
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #6
Hard to say at this point, without seeing the method. Is it really long? Maybe loop unrolling is screwing up, or some other optimization for release is screwing up. I would carefully examine the target settings for release and compare what's enabled (or not) compared to the debug version, like perhaps "Generate Position-Dependent Code". [edit] ... or "Compile for Thumb"

No, showing the assembly shouldn't do any harm at all. If you have some inline assembly in your code though, that could most definitely be causing a problem.
Quote this message in a reply
Apprentice
Posts: 8
Joined: 2010.09
Post: #7
the methode is about 250 lines long. i don't think that anything in the code is wrong because since yesterday it worked very well. i had only added one line of code and the error occured (doesn't matter what line of code i am adding even a simple NSLog causes the error).
i have an if/else block which is about 150 lines long. maybe this is too long for the compiler (but i don't think so). when i split this block in two blocks the error disappears.
strangly enough the error also dissapears when i put an additional "else if" (which is doing nothing) to a random else/if block in the methode. but that is stupid.
ok, my workaround for now is to split the large if/else block.
i hope this will work for the future because i am a little bit afraid of putting some new lines to the methode sometimes.
thanks for your advice and help.

http://www.microsia.de - become a micromusician and create molecular tunes
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #8
You really should try to find out what is causing this instead of doing the workaround, although, you gotta do what you gotta do if it's time to ship, I understand.

250 lines is certainly not too long. I don't know that there is any size limit, but I am just interested in whether or not you're doing something outrageous which might be throwing a curve-ball to the compiler. Out of curiosity, how many if/else's are there? I can't imagine the size of the block would be a problem. On the outside, it seems like the compiler is emitting miscalculated assembly somehow.

Did you try turning off Compile for Thumb? Compare the other target settings under the Code Generation section?

How about doing a project search for __asm__ just for the heck of it, to see if somehow that's being included from an external library? Again, we're blind without seeing the source.
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #9
Looking at this some more, yeah, this is obviously a compiler bug for sure. You might try duplicating that method in a small test program as close as you can and that might be able to reproduce it so you can more easily file the bug with Apple. I'd be sure to use the exact same symbol names too, just in case that might be throwing off the lexer/parser somehow (perhaps a German character in a symbol?). Also try to duplicate the exact target settings used. You said it doesn't do it for debug on the device, but it does for release, so there is obviously one target setting which triggers the compiler to choke when emitting ARM assembly. It could be anything, but this most definitely should not be happening. The compiler should know how to pass values to the ARM instruction which are not out of range, in any case. [edit] Again, this is all assuming you don't have any inline __asm__ snuck in there somewhere.
Quote this message in a reply
Apprentice
Posts: 8
Joined: 2010.09
Post: #10
compile for thumb is off (it's good for my performance). i had compared all the target settings and found no difference. after reading your last post i researched the settings and found that the

"Generate Position-Dependent Code"

flag was set in the release but not in the debug. unsetting this flag in the release setting and the error is gone. all other settings are definatly equal.
i don't have any ___asm___ code in my project.

here is the whole methode which caused the error:
as i said before, the error is caused even when i put five lines of simple NSLog anywhere in the methode (four lines are ok).

Code:
- (void)updatePhysic:(float)timeStep
{
    // Physic /////////////////////////////////////////////////////////////////////////
    if(gameOver == YES)
        gravity.Set(0.0f, [_sharedDirector gravityHeavy]);

    world->SetGravity(gravity);
    world->Step(timeStep*0.45f, 1, 1);
    //world->Step(timeStep*0.33333333f, 1, 1);

    //Iterate over the bodies in the physics world
    for (b2Body *b = world->GetBodyList(); b; b = b->GetNext())
    {
        if (b->GetUserData() != NULL)
        {
            AbstractEntity *oneEntity = (AbstractEntity *)b->GetUserData();
            
            if([[oneEntity objectName] compare:@"player"] == NSOrderedSame) {
                // Spieler Koordinaten zuweisen
                Point2f dotPos = Point2fMake(b->GetPosition().x*PTM_RATIO, b->GetPosition().y*PTM_RATIO);// [oneDot position];
                //[player setPosition:dotPos];
                
                // Wenn spieler zu weit nach links, bremsen
                if(b->GetLinearVelocity().x < 0.0f && dotPos.x < [valleyManager leftValleyEndXPos] + 8.0f)
                {
                    b2Vec2 vel;
                    vel.x = 5.0f;
                    vel.y = 0.0f;
                    b->SetLinearVelocity(vel);
                
                }
                
                if([player continentJump] == YES)
                {
                    b2Vec2 pos;
                    //pos.x = b->GetPosition().x+20.0f/PTM_RATIO;
                    pos.x = b->GetPosition().x;
                    pos.y = [player calcContinentJumpYPosForX:pos.x*PTM_RATIO]/PTM_RATIO;
                    b->SetTransform(pos,[player angle]);
                    pos.Set(80.0f, 0.0f);
//                    pos.y = 0.0f;
                    b->SetLinearVelocity(pos);
                    
                    // Spieler Winkel berechnen
                    GLfloat     playerAngle = [player calcContinentJumpAngleForX:b->GetPosition().x*PTM_RATIO];
                    playerAngle = [player angle] + (playerAngle-[player angle]) * 0.2f;
                    if(playerAngle < -0.8f) playerAngle = -0.8f;
                    [player setNewStateWithPosition:dotPos angle:playerAngle];
                }
                else
                {
                    if([player continentJumpEnd] == YES)
                    {
                        [player setContinentJumpEnd:NO];
                        Vector2f vel = [player endContinentJumpVelocityForX:b->GetPosition().x*PTM_RATIO];
                        b2Vec2 vel2;
                        vel2.Set(vel.x, vel.y);
                        vel2 *= 16.0f;
                        b->SetLinearVelocity(vel2);
                    }
                    
                    // Spieler Winkel berechnen
                    GLfloat     playerAngle = Vector2fAngle(Vector2fMake(b->GetLinearVelocity().x, b->GetLinearVelocity().y));

                    //playerAngle = [player angle] + (playerAngle-[player angle]) * 0.2f;
                    
                    if(playerAngle <= HALF_PI && playerAngle > 1.0f) playerAngle = 1.0f;
                    else if(playerAngle > HALF_PI && playerAngle < PI-1.0f) playerAngle = PI-1.0f;
                    else if(playerAngle >= -HALF_PI && playerAngle < -0.8f) playerAngle = -0.8f;
                    else if(playerAngle < -HALF_PI && playerAngle > -PI+1.0f) playerAngle = -PI+1.0f;
                    
                    
                    
                    //if(playerAngle < -0.8f) playerAngle = -0.8f;
                    [player setNewStateWithPosition:dotPos angle:playerAngle];
                
                    // Wenn der Spieler hoch fliegt, kraft auf ihn wirken lassen
                    GLfloat dist = [player newPosition].y - [valleyManager groundHightAtX:[player newPosition].x];
                    b2Vec2 highGravity, pos;
                    pos = b->GetPosition();
//                    if(dist > 1000) {
//                        highGravity.Set(0.0f, -800);
//                        b->ApplyForce(highGravity, pos);
//                    }
                    if(dist > 600.0f)
                    {
//                        GLfloat grav = (dist-600.0f) / 400.0f;
//                        highGravity.Set(0.0f, -(grav*1000.0f));
//                        b->ApplyForce(highGravity, pos);
                        
                        GLfloat grav = (dist-600.0f) / 300.0f;
                        b2Vec2 playerVel = b->GetLinearVelocity();
                        if(playerVel.y > 0.0f)
                        {
                            playerVel.y -= grav;
                            b->SetLinearVelocity(playerVel);
                        }
                        
                    }
                    highGravity.Set(0.0f, -(dist*0.3f));
                    b->ApplyForce(highGravity, pos);
                    
                    // wenn der spieler am continentende zu hoch fliegt, ihn abbremsen
                    if([player newPosition].x > [valleyManager continentEndPos].x-6400.0f && dist > 400.0f)
                    {
                        GLfloat grav = (dist-400.0f) / 50.0f;
                        b2Vec2 playerVel = b->GetLinearVelocity();
                        if(playerVel.y > 0.0f)
                        {
                            playerVel.y -= grav;
                            b->SetLinearVelocity(playerVel);
                        }
                    }
                }
//            }
//            
//            if([[oneEntity objectName] compare:@"player"] == NSOrderedSame)
//            {

                // speed coins gegessen?
                if([entityManager eatSpeedCoin] == YES)                    
                {
                    [entityManager setEatSpeedCoin:NO];
                    b2Vec2 playerVel = b->GetLinearVelocity();
                    playerVel.Normalize();
                    playerVel *= 150.0f;
                    b->ApplyLinearImpulse(playerVel, b->GetPosition());                    
                }

                // Fanden Collisionen statt?
                for (b2ContactEdge *ce = b->GetContactList(); ce; ce = ce->next)    
                {                    
                    if([valleyManager groundTypeAtX:[player newPosition].x] == BOOST)
                    {
                        b2Vec2 playerVel = b->GetLinearVelocity();
                        playerVel.Normalize();
                        playerVel *= 5.0f;
                        b->ApplyLinearImpulse(playerVel, b->GetPosition());
                    } else if ([valleyManager groundTypeAtX:[player newPosition].x] == MEGA_BOOST)
                    {
                        b2Vec2 playerVel = b->GetLinearVelocity();
                        b2Vec2 oldPlayerVel = playerVel;
                        playerVel.Normalize();
                        playerVel *= 80.0f;
                        
                        // nur speed setzen wenn wirklich schneller als vorher
                        if(playerVel.LengthSquared() > oldPlayerVel.LengthSquared())
                            b->SetLinearVelocity(playerVel);
                    }
                }
                                
                // Hat die Nacht den Spieler eingeholt? Dann spieler fallen lassen
                if(nightXPos > [player newPosition].x)
                {
                    if(gameOver == NO)
                    {
                        gameOver = YES;
                        [player goSleep];
                    }
                    b2Vec2 vel = b->GetLinearVelocity();
                    vel.x = 0.0f;
                    if(vel.y > 0.0f) vel.y = 0.0f;
                    b->SetLinearVelocity(vel);
                }
            }
        }    
    }

    // Die Nacht vorruecken lassen
    if([player continentJump] == NO && nightXPos-scrollX < 500.0f)
    {
        nightXPos += nightSpeed;
        nightSpeed += 0.0025f;
    }
    else if(nightXPos-scrollX >= 500.0f)
    {
        if(gameOverScreen == NO)
        {
            gameOverScreen = YES;
            gameOverScreenSlideY = 320.0f;
            [buttonManager activateButtonWithID:replayButton];
            [buttonManager activateButtonWithID:menuButton];
            [_sharedDirector checkAndPutScoreToHighscore:(int)[player score]];
        }
    }
    
//    // nacht erreicht game over
//    else if(nightXPos-scrollX >= 50000.0f)
//    {
//        if(gameOverScreen == NO)
//        {
//            gameOverScreen = YES;
//        }
//    }
    
    // wenn night resettet wird, night zurucksetzen
//    if(nightSpeed == 0.0f) nightXPos = nightTargetXPos + (nightXPos - nightTargetXPos) * 0.999f;
//    nightSpeed += 0.005f;
    
    [player updateWithValleyManager:valleyManager scrollX:scrollX scrollY:scrollY];

    [player setHeightFromGroundHeight:[valleyManager groundHightAtX:[player position].x]];
    if([player perfectTrigger] == YES)
    {
        perfectImageAlpha = 255.0f;
        perfectImageX = 240.0f + 64.0f;
        perfectText = int(RANDOM_0_TO_1() * 6.0f);
        [player setPerfectTrigger:NO];
        [bonusPointsText release];
        if([player feverMode] == NO)
            bonusPointsText = [NSString stringWithFormat:@"+%1.0f",PERFECT_VALLEY_SCORE];
        else
            bonusPointsText = [NSString stringWithFormat:@"+%1.0f",PERFECT_VALLEY_SCORE*FEVER_MULTIPLOKATOR];
        [bonusPointsText retain];
        
        [bonusText release];
        bonusText = @"perfect slide";
        [bonusText retain];

    }
    if([player cloudTouchTrigger] == YES)
    {
        cloudTouchImageX = 240.0f + 64.0f;
        [player setCloudTouchTrigger:NO];
        [bonusPointsText2 release];
        if([player feverMode] == NO)
            bonusPointsText2 = [NSString stringWithFormat:@"+%1.0f",CLOUD_TOUCH_SCORE];
        else
            bonusPointsText2 = [NSString stringWithFormat:@"+%1.0f",CLOUD_TOUCH_SCORE*FEVER_MULTIPLOKATOR];

        [bonusPointsText2 retain];
        
        [bonusText2 release];
        bonusText2 = @"cludtouch";
        [bonusText2 retain];
    }
    perfectImageAlpha *= 0.9f;
    if(perfectImageAlpha < 1.0f) perfectImageAlpha = 0.0f;
    
    if(perfectImageX > 0.1f) perfectImageX *= 0.8f;
    else if(perfectImageX <= 0.1f && perfectImageX > 0.0f) perfectImageX *= -1.0f;
    else if(perfectImageX > -400.0f) perfectImageX *= 1.2f;
    
    if(cloudTouchImageX > 0.1f) cloudTouchImageX *= 0.8f;
    else if(cloudTouchImageX <= 0.1f && cloudTouchImageX > 0.0f) cloudTouchImageX *= -1.0f;
    else if(cloudTouchImageX > -400.0f) cloudTouchImageX *= 1.2f;
    
// dayOver screen sliden
    if(gameOverScreen == YES)
    {
        if(gameOverScreenSlideY > 0.1f) gameOverScreenSlideY *= 0.9f;
        else gameOverScreenSlideY = 0.0f;
    }

}

many thanks for your help. i am again and again impressed by some users of forums who help other people on this earth with such a ferventness. thanks.

http://www.microsia.de - become a micromusician and create molecular tunes
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #11
(Oct 13, 2010 07:37 AM)spuckfunkel Wrote:  compile for thumb is off (it's good for my performance). i had compared all the target settings and found no difference. after reading your last post i researched the settings and found that the

"Generate Position-Dependent Code"

flag was set in the release but not in the debug. unsetting this flag in the release setting and the error is gone.

That definitely helps narrow it down!

Looking at your code, I don't see anything obviously weird. It looks fine to me.

So this should be filed as a bug. Now the only thing that could help for filing the bug report is trying to reproduce it in a test program. As I suggested earlier, maybe you can duplicate that method exactly in the test program. If you can, that would be fantastic for filing the bug report.

In the meantime, if it were me, my "workaround" would be to simply leave Generate Position-Dependent Code unchecked for release.
Quote this message in a reply
Member
Posts: 166
Joined: 2009.04
Post: #12
(Oct 13, 2010 08:05 AM)AnotherJake Wrote:  
(Oct 13, 2010 07:37 AM)spuckfunkel Wrote:  compile for thumb is off (it's good for my performance). i had compared all the target settings and found no difference. after reading your last post i researched the settings and found that the

"Generate Position-Dependent Code"

flag was set in the release but not in the debug. unsetting this flag in the release setting and the error is gone.

That definitely helps narrow it down!

Looking at your code, I don't see anything obviously weird. It looks fine to me.

So this should be filed as a bug. Now the only thing that could help for filing the bug report is trying to reproduce it in a test program. As I suggested earlier, maybe you can duplicate that method exactly in the test program. If you can, that would be fantastic for filing the bug report.

In the meantime, if it were me, my "workaround" would be to simply leave Generate Position-Dependent Code unchecked for release.

If you do a search you will find that this issue has already been reported ( and fixed) although the fix is not out yet ( I am talking about gcc folks - I am not sure how it relates to the branch Apple is using)
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #13
It still needs to be reported to Apple. Apple is not tracking the GCC head any more, so bug fixes to GCC will NOT automatically appear in future versions of Apple's GCC.

I would work around the bug by shortening the method rather than turning PIC on. PIC is likely to be bad for performance.

warmi: is the issue you found to do with something simple like too many floating point constants that could be worked around by making a few locals?
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #14
(Oct 13, 2010 08:40 AM)OneSadCookie Wrote:  I would work around the bug by shortening the method rather than turning PIC on. PIC is likely to be bad for performance.

That's true. My initial thought was that I'd be too paranoid at that point, but you're right that it's probably still worth it.
Quote this message in a reply
Apprentice
Posts: 8
Joined: 2010.09
Post: #15
ok i have to do the workaround. PIC is really a performance killer for my app (runs at 60fps). it scares me a little bit that also compilers have bugs.
at the moment i have no time for reproducing the bug in a test programm because my money is floating away and i need to release my app.
after the release i will do this bug report.

many thanks to all of you. this forum is great!
have a good day.

http://www.microsia.de - become a micromusician and create molecular tunes
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  touches offset? Jamie W 11 11,498 Aug 18, 2011 10:23 AM
Last Post: MattDiamond
  Offset the text in a UITextField??? Toontingy 0 4,589 Apr 25, 2010 08:44 PM
Last Post: Toontingy
  do you know info about iPad and new A4 processor? riruilo 26 11,151 Feb 17, 2010 12:50 PM
Last Post: warmi