views:

569

answers:

1

My program works the way I want it to on both the iPhone simulator and the iPhone itself when using the debug build. However when I change it to the release build, its works on the iPhone simulator but not on the device. I'm trying to animate a ball across the screen with a timer and the ball should bounce off the sides if it collides with the edges of the screen. This works fine for the debug builds but the release build only works on the simulator and not the device. The ball does not even move on the device with the release build.

I have a feeling this has to do with the optimization level that is changed when switched from a debug to a release build. If this is true how can I change my code to better suit the optimization level?

The view controller is called with initWithNibName: which contains:

CGRect ballRect = CGRectMake(133, 424, 55, 56); 
newBall = [[Ball alloc] initWithFrame: ballRect];
[self.view addSubview: newBall];
[self setImage: [UIImage imageNamed: @"Red.png"]];

Ball *newBall was declared in the interface file. The ball is shown correctly on the screen with the correct image on all builds.

The timer to move the ball is called when the user taps the screen:

-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event{
    touch = [touches anyObject];
    touchPoint = [touch locationInView: self.view];
    dx = touchPoint.x - newBall.center.x;
    dy = touchPoint.y - newBall.center.y;
    newBallTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0/50.0 target: self selector: @selector(moveBall) userInfo: nil repeats: YES];
}

CGPoint touchPoint, UITouch *touch, float dx, float dy and NSTimer *newBallTimer were declared in the interface file too.

Here is my code for moving the ball and detecting collisions:

-(void) moveBall
{    
    newBall.center = CGPointMake( newBall.center.x + dx, newBall.center.y + dy );

    // left boundary
    if( newBall.frame.origin.x <= 20 )
    {
        dx = abs(dx);
    }   
    else if( newBall.center.x >= 280 )  
    {
        dx = -abs(dx);
    }
}

On the release build on the device the ball doesn't move. Instead it seems to be sent to the bottom of the screen and stay there.

Any suggestions/solutions/ideas are highly appreciated. Thanks in advance!

A: 

How are you getting the release build onto your device? Or do you mean an Ad Hoc build?

In either case, do you have any #define or #ifdef code blocks that are perhaps being commented out when you do the release build?

Another possibility is doing actual logic in a NSAssert and then turning off asserts in the release build. When you turn off asserts any code in that assert will not be called.

Marcus S. Zarra
Thanks for your reply. To put the release build on the device I set the active SDK to iPhone Device 3.0 and the active configuration to Release in Xcode.I do have #define statements as well as #include but none of them have been commented out. I dont use NSAssert.