1

I'm trying to load 4 UIImageView to run different animations. Each animation is composed of 164 png of 6 KB of size each one.

I've tested in instruments and when runs in simulator works fine and the size in memory is less than 5,5 MB.

But when runs in the iPad the app just crashes without log message or memory warnings. I've tested in instruments and the size in memory is less than 5 MB before crash.

Here the code.

-(void)startAnimations
{
    OTAnimationProvider *ani = [[OTAnimationProvider alloc] init];

    int a;

    for (a=0;a<[teams CountY];a++)
    {
        UIImageView *animationTeam = [[UIImageView alloc] initWithFrame:CGRectMake(10, 300 + (40 * a), 1004, 300)];

        int idTeam = [[teams getValueByName:@"IdTeam" posY:a] intValue];

        [animationTeam setAnimationImages:[ani animationWithName:[NSString stringWithFormat: @"OTScoreBoardLeague_%d_%d_",idTeam,a+1] frameCount:164 step:2]];

        [animationTeam setAnimationDuration:animationPlayersTime];

        [animationTeam setAnimationRepeatCount:1];

        [animationTeam startAnimating];

        [self.view addSubview:animationTeam];

        [animationTeam release];
    }

    [ani release];
}

OTAnimationProvider object is only an object with a method that returns the images array of the animation.

Any idea of what I'm doing wrong :(

Thanks.

UPDATE---

I've tried to use an animation Atlas with CALayer object. But I'm still obtaining the same results.

In device the app crashes without any error message in debug.

This is the code:

CALayer *layer = [CALayer layer];

CGImageRef img = [[UIImage imageNamed:@"OTScoreBoardLeagueAtlasTeam_1_1.png"]CGImage];

layer.contents = (id)img;

CGSize size = CGSizeMake( 1004, 300 ); // size in pixels of one frame
CGSize normalizedSize = CGSizeMake( size.width/CGImageGetWidth(img), size.height/CGImageGetHeight(img) );

layer.bounds = CGRectMake( 0, 0, size.width, size.height );
layer.contentsRect = CGRectMake( 10, 300 + (20 * a), normalizedSize.width, normalizedSize.height );

CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"sampleIndex"];

anim.fromValue = [NSNumber numberWithInt:1]; // initial frame
anim.toValue = [NSNumber numberWithInt:165]; // last frame + 1

anim.duration = 8.0f; // from the first frame to the 6th one in 1 second
anim.repeatCount = 0; // just keep repeating it
anim.autoreverses = NO; // do 1, 2, 3, 4, 5, 4, 3, 2

[layer addAnimation:anim forKey:nil]; // start

[self.view.layer addSublayer:layer];

Any ideas?

Thanks.

NemeSys
  • 555
  • 1
  • 10
  • 28
  • What are the dimensions of the PNGs, in pixels? – rob mayoff Feb 19 '12 at 01:04
  • Do these images have a lot of transparent areas? – Sergey Kalinichenko Feb 19 '12 at 01:10
  • in px are 1004 x 300 px. An yes indeed have many transparent areas. – NemeSys Feb 19 '12 at 01:25
  • Does reducing the number of images eventually prevent the crash? Have you tried adding simple printing to detect where the application stops running? What happens when you run the code in the debugger (attached to Xcode/gdb)? – Josh Rosen Feb 19 '12 at 01:35
  • There appears to be [an old-standing issue](http://www.iphonedevsdk.com/forum/iphone-sdk-development/7546-virtual-memory-leak-when-using-uiimageview-setanimationimages.html) with iOS devices consuming a lot of resources when animating images with transparency, compared to same images without transparency. This would be the first thing I'd try. – Sergey Kalinichenko Feb 19 '12 at 01:47
  • I would also try combining my images in a single "texture atlas": I tried the approach from [this article](http://mysterycoconut.com/blog/2011/01/cag1/), and it worked very well for me. My images are *a lot* smaller (64*64 pixels). – Sergey Kalinichenko Feb 19 '12 at 01:51
  • I tried, to load less images that animation have. The parameter Step of the OTAnimationProvider object skips the indicated number of images of the animation. If I use a value of 6 works. But I'm skipping 6 frames of every 7 and the animation shows poor. – NemeSys Feb 19 '12 at 12:41
  • Just to clear up some bad advice, a texture atlas and using alpchannel or not will not have any effect on the root problem. You are simply using too much memory and as a result, your app crashes. Read more detailed info and specific solutions here http://stackoverflow.com/questions/8112698/how-to-do-animations-using-images-efficiently-in-ios/17129053#17129053 – MoDJ Jun 18 '13 at 15:53

0 Answers0