0

I'm encountering a very weird error causing my app to crash. I have created a custom SKSpriteNode called heroSpriteNode. Here is my initialization:

 (id) init
{
 if (self = [super init])
{
    [self loadAnimations];
    SKTexture *temp = self.gorillaStandingFrames[0];
    self = [heroSpriteNode spriteNodeWithTexture:temp];
    [self setUpHeroDetails];
}
return self;
}

The error is occurring when attempting to run an action on "self" the custom SkSpriteNode, like this:

-(void)jump
{

NSLog(@"Jump Tap!");

if(self.isOnTheGround)
{
    self.physicsBody.velocity = CGVectorMake(0, 0);
    self.physicsBody.angularVelocity = 0;
    self.timedJump=NO;
    [self.physicsBody applyImpulse:CGVectorMake(0, 350)];
    [self removeActionForKey:@"walkingInPlaceBear"];
    [self jumpingGorilla2]; // HERE IS THE ERROR
    self.isOnTheGround=NO;
    self.isRunning=NO;
    self.isStanding=NO;
    self.jumpFixTimer = [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(flipTimedJumpBoolean) userInfo:nil repeats:NO];

}

}

I know this animation (and other animations I run) is the issue, because when I comment out that line the game runs fine.

Here is how I am loading the textures and creating an action:

-(void)loadJumpAnimation2
{
NSMutableArray *jumpFrames = [NSMutableArray array];
SKTextureAtlas *gorillaAnimatedAtlas = [SKTextureAtlas atlasNamed:@"mainCharJump"];
int numImages = gorillaAnimatedAtlas.textureNames.count;
for (int i=2; i <= numImages; i++) {
    NSString *textureName = [NSString stringWithFormat:@"j%d", i];
    SKTexture *temp = [gorillaAnimatedAtlas textureNamed:textureName];
    [jumpFrames addObject:temp];
}
self.gorillaFlyingJump = jumpFrames;

}


-(void)jumpingGorilla2
{

[self runAction:[SKAction repeatActionForever:
                         [SKAction animateWithTextures:self.gorillaFlyingJump
                                          timePerFrame:0.25f
                                                resize:NO
                                               restore:YES]]       withKey:@"jump"];

return;
}

When it crashes there is no crash report in the logger, only a popup message in Xcode that is of type: 9 SIGKILL. It seems like this could be a memory issue related to how the animation frames are being stored? The animations ran fine on a standard SkSpriteNode, then after refactoring much of the code into a custom SkSpriteNode, I can no longer apply animations. Any ideas? Thank you.

UPDATE:

I've created another class to try to isolate the issue I'm having, I will post the code below with comments.

Here is the entire test class I created:

#import "heroTestNode.h"

@implementation heroTestNode


- (id) init
{
if (self = [super init])
{
    [self loadAnimations];
    SKTexture *temp = self.gorillaWalkingFrames[0];
    self = [heroTestNode spriteNodeWithTexture:temp];
}
return self;
}



-(void)loadAnimations
{

 NSMutableArray *walkFrames = [NSMutableArray array];
 SKTextureAtlas *gorillaAnimatedAtlas = [SKTextureAtlas     atlasNamed:@"mainCharRun2"];


int numImages = gorillaAnimatedAtlas.textureNames.count;
NSLog(@"Here are how many animation frames: %d", numImages);

for (int i=1; i <= numImages; i++) {
    NSString *textureName = [NSString stringWithFormat:@"r%d", i];
    SKTexture *temp = [gorillaAnimatedAtlas textureNamed:textureName];
    [walkFrames addObject:temp];
}
self.gorillaWalkingFrames = walkFrames;
}

-(void)walkingGorilla // running this is causing the SIGKILL 9 crash
{

[self runAction:[SKAction repeatActionForever:
                 [SKAction animateWithTextures:self.gorillaWalkingFrames
                                  timePerFrame:0.1
                                        resize:NO
                                       restore:YES]]   withKey:@"test"];
return;
}



@end

Here is the interface:

#import <SpriteKit/SpriteKit.h>

@interface heroTestNode : SKSpriteNode
@property NSMutableArray *gorillaWalkingFrames;
-(void)walkingGorilla;

@end

And finally, here is how I am instantiating it:

heroTestNode *test = [[heroTestNode alloc] init];
test.position =  CGPointMake((self.frame.size.width/2)+30,self.frame.size.height/3);
[self addChild:test];
[test walkingGorilla]; // this is causing the SIGKILL 9 crash

This causes the it to freeze "compressing" the view into the bottom left corner of my iPad and going unresponsive. I have no idea what would be causing this.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Solsma Dev
  • 481
  • 6
  • 22
  • Just curious... What happens if you try running the offending animation, but **without** removing the action for key `@"walkingInPlaceBear"` first? Still crash? – Nicolas Miari Feb 20 '15 at 01:58
  • Hi, there is still the crash. I've isolated the animation in a separate class to insure that the issue isn't being caused by something else. I will add an update to clarify the problem. – Solsma Dev Feb 20 '15 at 02:02
  • Ok, I added an update that should isolate the animation issue. I've posted the whole class code including interface as well as how I am instantiating the class. – Solsma Dev Feb 20 '15 at 02:08

0 Answers0