开发者

Game crashes after being stressed

I am in trouble with my game now, it keep crashing when I stress it too much. Meaning I crazily sliding, moving, or tapping my fingers on the screen, it will crash. The crash has no rule. I tried to detect, in the console log shows the message low memory warning. I know it is about the memory stuff, but I am using Cocos2D to make this game, I followed the instructions in best practice. It seems smoother after that but still crashes if I do like what I mentioned above. If like in Cocoa, we have alloc and release, but it Cocos2D, I think we don't need to do so. My game is just loading images, and make animation after touching.

//where the fingers ended , this will determine the correct actions made. 
-(BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)events
{
    int touchCount = 0;
    NSSet *allTouches3 = [events allTouches];
    for( UITouch *touch in allTouches3)
    {
        location3 = [touch locationInView: [touch view]];
        location3 = [[Director sharedDirector] convertCoordinate: location3];

        NSLog(@"end TOUCHed x2: %3.3f, y2: %3.3f",location3.x,location3.y);
        touchCount++;
    }
    [self removeChildByTag:kTagWord cleanup:YES]; 

    timeEnd = [NSDate timeIntervalSinceReferenceDate];
    touchDuration = timeEnd - timeStart;
    //float rangeX = location3.x - location.x;
    rangeY2 = location3.y - location.y;

    //loading the succesful opened box with 2 touches same direction 
    if ((touchCount > 0 && touchCount ==2) && (rangeY2 > 0.0 && rangeY2 <15.0))
    {
        box++;
        self.isTouchEnabled = NO;
        [self removeErrorText];

        if (box == 1)
        {
            [self loadingTheRest];
        }
        else if (box == 2)
        {
            [self loadingTheRest1];
        }
        else if (box ==3)
        {
            [self loadingTheRest2];
        }

        if (currentBox == 0 )
        {
            [self addText];
            [self boxOpenAnimation];
            [self schedule:@selector(enableTheTouches) interval:1.0f];

        } else if(currentBox == 1 )
        {
            [self addText1];
            [self boxOpenAnimationPink];
            //[self schedule:@selector(winGame) interval:0.4f];
            [self schedule:@selector(enableTheTouches) interval:1.0f];

        }
    }
}

and this is an example of a loading box

-(void)loadingTheRest
{
    //LOADING OTHER COLOURS
    AtlasSpriteManager *managerPink  = [AtlasSpriteManager spriteManagerWithFile:@"PinkNew.png"];
    AtlasSpriteManager *error2  = [AtlasSpriteManager spriteManagerWithFile:@"PinkErrors.png"];
    [self addChild:managerPink z:1 tag:kTagSpriteManagerPink ];
    [self addChild:error2 z:1 tag:kTagSpriteErrorPink ];

}

-(void)boxOpenAnimation
{
    if (isBusy==YES)
    {
            return;
    }
    isBusy=YES;

    [self removeBoxColours];
    AtlasSpriteManager *mrg = (AtlasSpriteManager *)[self getChildByTag:kTagSpriteManager];
    AtlasSprite *box = [AtlasSprite spriteWithRect:CGRectMake(482, 322,480, 320) spriteManager:mrg];
    box.position = ccp(240,160);
    [mrg addChild:bra z:1 tag:1984];

    AtlasAnimation *animation = [AtlasAnimation animationWithName:@"open" delay:0.1];

    [animation addFrameWithRect: CGRectMake(1, 322, 480, 320) ];    
    [animation addFrameWithRect:CGRectMake(482, 1, 480, 320)];
    [animation addFrameWithRect:CGRectMake(1, 1, 480, 320)];
    [animation addFrameWithRect:CGRectMake(1, 643, 480, 320)];
    id action = [Animate actionWithAnimation:animation];

    [box runAction:action];
    [self loadingTheRest];
    isBusy=NO;

}

Please share your knowledge with me if you know about the reasons why my g开发者_StackOverflowame crashes. Thank you so much


You don't have the code here, but my guess is that you are dividing by 0 with the value here.

touchDuration = timeEnd - timeStart;

According to Apple, timeIntervalSinceReferenceDate returns seconds which means that if you call it within a second timeEnd - timeStart == 0.

I deduced this from your description of the crashes.


Make your code respond to the DidRecieveMemoryWarning message. Then when you are getting low on memory the OS should (it won't always, especially if your memory usage goes through the roof quickly) notify you, and then you can get rid of objects that may have gone off screen or such.


I'd suggest you attach a debugger, disable catching first chance exceptions, enable grabbing second chance exceptions and then cause your crash. Debugger will show you the call stack of the crash.


Maybe your game is consuming too much memory? In such case, the system itself would just kill your game if anything else needs more memory and your game has taken all of it. Such situations would look like random crashes in your game.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜