Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-06-2012, 02:39 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 19
francis is on a distinguished road
Default [Sprite setString:]:unrecognized selector sent to instance & malloc_error_break

i have this app like doodlejump then i added monsters and projectiles and i have finished it

however im getting this 2 crashes.. one(sometimes) when the app opens this occurs :
Code:
[Sprite setString:]: unrecognized selector sent to instance
and the other is when i fire many projectiles this occurs:
Code:
malloc: *** error for object 0x5e99f00: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
i really dont know what to do now...

here's my game.m

Code:
- (id)init {
//      NSLog(@"Game::init");

        if(![super init]) return nil;

        gameSuspended = YES;

        AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];

        [self initPlatforms];

        AtlasSprite *bird = [AtlasSprite spriteWithRect:CGRectMake(608,16,44,32) spriteManager:spriteManager];
        [spriteManager addChild:bird z:4 tag:kBird];

        AtlasSprite *bonus;

        for(int i=0; i<kNumBonuses; i++) {
                bonus = [AtlasSprite spriteWithRect:CGRectMake(608+i*32,256,25,25) spriteManager:spriteManager];
                [spriteManager addChild:bonus z:4 tag:kBonusStartTag+i];
                bonus.visible = NO;
        }

//      LabelAtlas *scoreLabel = [LabelAtlas labelAtlasWithString:@"0" charMapFile:@"charmap.png" itemWidth:24 itemHeight:32 startCharMap:' '];
//      [self addChild:scoreLabel z:5 tag:kScoreLabel];

        BitmapFontAtlas *scoreLabel = [BitmapFontAtlas bitmapFontAtlasWithString:@"0" fntFile:@"bitmapFont.fnt"];
        [self addChild:scoreLabel z:5 tag:kScoreLabel];
        scoreLabel.position = ccp(160,430);

        [self schedule:@selector(step:)];
        [self schedule:@selector(update:)];

        isTouchEnabled = YES;
        isAccelerometerEnabled = YES;

        [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kFPS)];

        [self startGame];
        [self schedule:@selector(gameLogic:) interval:5.0];

        _targets = [[NSMutableArray alloc]init];
        _projectiles = [[NSMutableArray alloc]init];

        return self;
}

-(void)addTarget {

        Sprite *target = [Sprite spriteWithFile:@"komodo.png"];

        target.position = ccp(300,200);

        [self addChild:target];

        CGSize winSize = [[Director sharedDirector]winSize];
        int minX = target.contentSize.height/2;
        int maxX = winSize.height -target.contentSize.height/2;
        int rangeX = maxX - minX;
        int actualX = (arc4random() % rangeX) +minX;

        int minDuration = 2.0;
        int maxDuration = 4.0;
        int rangeDuration = maxDuration - minDuration;
        int actualDuration = (arc4random() % rangeDuration) + minDuration;

        id actionMove = [MoveTo actionWithDuration:actualDuration position:ccp(-target.contentSize.width,actualX)];
        id actionMoveDone = [CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
        [target runAction:[Sequence actions:actionMove, actionMoveDone,nil]];
        target.tag = 1;
        [_targets addObject:target];

}

-(void)spriteMoveFinished:(id)sender {

        Sprite *sprite = (Sprite *)sender;
        [self removeChild:sprite cleanup:YES];

        if (sprite.tag == 1) {
                [_targets removeObject:sprite];

        } else if (sprite.tag == 2) {
                [_projectiles removeObject:sprite];
        }
}
-(void)gameLogic:(ccTime)dt {
        [self addTarget];

}

-(void) update:(ccTime)dt {
        AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];
        AtlasSprite *bird = (AtlasSprite *) [spriteManager getChildByTag:kBird];

        CGRect birdRect = CGRectMake(bird.position.x - (bird.contentSize.width/2), bird.position.y - (bird.contentSize.height/2), bird.contentSize.width/1.8,bird.contentSize.height/1.5);

        NSMutableArray *targetsToDelete = [[NSMutableArray alloc]init];
    for (Sprite *target in _targets) {
                CGRect targetRect = CGRectMake(
                                                                           target.position.x - (target.contentSize.width/2),
                                                                           target.position.y - (target.contentSize.height/2),
                                                                           target.contentSize.width,
                                                                           target.contentSize.height);

                        NSMutableArray *projectilesToDelete = [[NSMutableArray alloc]init];
                        for(Sprite *projectile in _projectiles) {
                                CGRect projectileRect = CGRectMake(projectile.position.x - (projectile.contentSize.width/2),projectile.position.y - (projectile.contentSize.height/2), projectile.contentSize.width, projectile.contentSize.height);

                                if(CGRectIntersectsRect(birdRect,targetRect)) {
                                        NSLog(@"HIT!");
                                        gameSuspended = YES;
                                        [self showHighscores];
                                }

                                if(CGRectIntersectsRect(targetRect,projectileRect )) {
                                NSLog(@"Boom Boom Pow");
                                        [targetsToDelete addObject:target];
                                }

                        for (Sprite *target in targetsToDelete) {
                                [_targets removeObject:target];
                                [self removeChild:target cleanup:YES];
                        }
                        if(targetsToDelete.count > 0) {
                                [projectilesToDelete addObject:projectile];
                        }
                        [targetsToDelete release];
                }
                for(Sprite *projectile in projectilesToDelete) {
                        [_projectiles removeObject:projectile];
                        [self removeChild:projectile cleanup:YES];
                }
                [projectilesToDelete release];

                }
        }

-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];
        AtlasSprite *bird = (AtlasSprite*)[spriteManager getChildByTag:kBird];

        UITouch *touch = [touches anyObject];
        CGPoint location = [touch locationInView:[touch view]];
        location = [[Director sharedDirector]convertCoordinate:location];

        CGSize winSize = [[Director sharedDirector]winSize];
        Sprite *projectile = [Sprite spriteWithFile:@"bullet.png"];
        projectile.position = ccp(bird.position.x,bird.position.y);

        int offX = location.x - projectile.position.x;
        int offY = location.y - projectile.position.y;

        [self addChild:projectile];

        int realX = winSize.width + (projectile.contentSize.width/2);
        float ratio = (float) offY / (float) offX;
        int realY = (realX *ratio) + projectile.position.y;
        CGPoint realDest = ccp(realX, realY);

        int offRealX = realX - projectile.position.x;
        int offRealY = realY - projectile.position.y;
        float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY));
        float velocity = 480/1;
        float realMoveDuration = length/velocity;

        [projectile runAction:[Sequence actions:[MoveTo actionWithDuration:realMoveDuration position:realDest],
                                                   [CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)], nil]];
        NSLog(@"Shoot!");
        projectile.tag = 2;
        [_projectiles addObject:projectile];

}
i badly need help. because i have been working on this for days then when i finally finished it

this crashes appear.... :c hope pro's would look and answer THANKS SO MUCH
francis is offline   Reply With Quote
Reply

Bookmarks

Tags
cocos2d, iphone, pro

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 403
10 members and 393 guests
buggen, guusleijsten, j.b.rajesh@gmail.com, morterbaher, QuantumDoja, sacha1996, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,673
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, morterbaher
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:35 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0