Looks to be a bug in SKTexture
as discussed in the dev forums here. Following the lldb trace, I would guess it's a memory management problem with how it allocates the image data buffers when using filters. If you really want to avoid using SKEffectNode
, this code should get you around it by handling the filters directly and avoiding the reliance on SKTexture
.
UIImage *ship = [UIImage imageNamed:@"Spaceship.png"];
CIImage *shipImage = [[CIImage alloc] initWithImage:ship];
CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone" keysAndValues:kCIInputImageKey, shipImage, @"inputIntensity", [NSNumber numberWithFloat:0.6], nil];
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *out = [filter outputImage];
CGImageRef cg = [context createCGImage:out fromRect:[out extent]];
SKTexture *texDone = [SKTexture textureWithCGImage:cg];
Tested and working here, but probably easier to just use the SKEffectNode
code you posted. Not sure which is more efficient, you'll have to play around with them.
// adding the texture to a sprite with above filter works
SKSpriteNode *spriteToFilter = [SKSpriteNode spriteNodeWithTexture:texDone];
[self addChild:spriteToFilter];
spriteToFilter.position = CGPointMake(200, 200);