1

I'm using a particle emitter in an iPad project (not using SpriteKit), the particle emitter is generated inside a UIImageView and since iOS 9 this emitter is making the whole app crash. Actually, the whole iPad is crashing, the image freezes and nothing can make the iPad unfreeze short of restarting the iPad.

If I bring the birthrate down from 19.0f to 6.0f the iPad stops crashing. The image I am using is a png of 256 × 256 in size, I'm not sure if that might play a role in it crashing.

Everything was working fine in iOS 8.

I'm currently on iOS 9.0.1 on an iPad Air 2, using Xcode 7.0.1.

+(void)smogGeneral:(UIImageView *)myView{
    [myView setNeedsDisplay];
    CALayer *rootLayer = [myView layer];
    CALayer *emitterSuperLayer = [CALayer layer];
    emitterSuperLayer.bounds = myView.bounds;
    emitterSuperLayer.sublayerTransform = CATransform3DMakeScale(1.0f, -1.0f, 1.0f);
    [rootLayer addSublayer:emitterSuperLayer];
    CGFloat midX = floorf(CGRectGetMidX(myView.bounds));
    CGFloat midY = floorf(CGRectGetMidY(myView.bounds));
    [emitterSuperLayer setPosition:CGPointMake(midX, midY)];

    CAEmitterLayer *whiteSmokeEmitter = [CAEmitterLayer layer];
    [whiteSmokeEmitter setName:@"whiteSmokeEmitter"];
    whiteSmokeEmitter.zPosition = 0.00f;
    whiteSmokeEmitter.emitterPosition = CGPointMake(300, 300);
    whiteSmokeEmitter.renderMode = kCAEmitterLayerBackToFront;
    whiteSmokeEmitter.emitterSize = CGSizeMake(10.00f, 10.0f);
    whiteSmokeEmitter.velocity = 0.05f;
    whiteSmokeEmitter.emitterMode = kCAEmitterLayerOutline;
    whiteSmokeEmitter.emitterShape = kCAEmitterLayerRectangle;

    CAEmitterCell *puffCell = [CAEmitterCell emitterCell];
    [puffCell setName:@"puffCell"];
    puffCell.contents = (__bridge id)[[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"smokeCell" ofType:@"png"]] CGImage];;
    CGColorRef colorRefPuffcell = [UIColor colorWithRed:0.99f green:0.98f blue:1.00f alpha:0.10f].CGColor;
    puffCell.color = colorRefPuffcell;
    puffCell.scale = 0.2f;
    puffCell.emissionLongitude = 1.84f;
    puffCell.emissionRange = 1.11f;
    puffCell.lifetime = 16.0f;
    puffCell.birthRate = 19.0f;
    puffCell.scaleSpeed = 0.15f;
    puffCell.velocity = 2.56f;
    puffCell.velocityRange = 9.80f;
    puffCell.xAcceleration = 9.15f;
    puffCell.yAcceleration = -0.01f;

    whiteSmokeEmitter.emitterCells = @[puffCell];
    [emitterSuperLayer addSublayer:whiteSmokeEmitter];
}
C.O.
  • 2,281
  • 6
  • 28
  • 51
PhilBlais
  • 1,076
  • 4
  • 13
  • 36
  • 1
    I don't see anything wrong in your code. Have you tried using a smaller png file (say 128x128)? Can you increase then the birthrate of the emitter without crashing? If you can, then the problem could be that the iPad runs out of memory due to a bug in Metal (because CAEmitterLayer uses Metal in iOS 9, right?). – RoberRM Sep 30 '15 at 23:09
  • I'm going to try with a 64 x 64 image, it's weird I just did a build on an iPad Air on iOS 8.4.1 and it works flawlessly. – PhilBlais Oct 01 '15 at 02:36
  • Well? Did it work? Did you find another solution? – RoberRM Oct 05 '15 at 23:38
  • Actually, I've talked with other people that have an iPad Air 2 and they have none of the issues running this. What's weird is that the problem began right after I updated to iOS 9. Anyhow, I'm going to the Apple Store tomorrow so they can analyze my iPad. I'll comment back after that. – PhilBlais Oct 06 '15 at 04:35
  • So in the end there was no software issue, it seems that passing to iOS 9 might have triggered an existing defect. So the problem was hardware, I'm running the same code on the iPad Air 2 exchange they gave me and everything works flawlessly – PhilBlais Oct 07 '15 at 04:47
  • 1
    Oh, well, thank you for sharing. It is good to know that this weird behaviors can be due to hardware problems... I guess... :D – RoberRM Oct 07 '15 at 20:25

0 Answers0