开发者

UIImageView animation crashing (sigabrt)

开发者 https://www.devze.com 2023-04-12 17:52 出处:网络
Any idea why this crashes? What am I doing wrong? Thanks! -(IBAction)animationOneStart { NSMutableArray* arrayOfImages = [[NSMutableArray alloc]initWithCapacity:10];

Any idea why this crashes? What am I doing wrong?

Thanks!

-(IBAction)animationOneStart { 

NSMutableArray* arrayOfImages = [[NSMutableArray alloc]initWithCapacity:10];

for(int count = 1; count <= 22; count++)
{
    NSString *path = [NSString stringWithFormat:@"testDance3_%03d.jpg", count];
    UIImage* img = [[UIImage alloc]initWithContentsOfFile:path];
    [arrayOfImages addObject开发者_JAVA技巧:img];
    [img release];
}

loadingImageView.animationImages = arrayOfImages;
[arrayOfImages release];

loadingImageView.animationDuration = 3;
loadingImageView.animationRepeatCount = 1; //Repeats indefinitely

[loadingImageView startAnimating];

loadingImageView.animationImages = nil;
[loadingImageView release];
}


Try initializing your NSMutableDictionary with capacity for the same quantity of object's you'll be storing in it. If that doesn't work, I'd try to comment out these two lines:

//loadingImageView.animationImages = nil;
//[loadingImageView release];

In the scope of this code, your other calls appear balanced. But we can't see what's happening inside loadingImageView, and so my guess is that either the loadingImageView itself or it's animations are being released prematurely.


I can't see enough code confirm this, but a couple things that are suspicious are here:

[loadingImageView startAnimating];

loadingImageView.animationImages = nil;
[loadingImageView release];

So, while the animation is running, you are releasing the images that are being animated? Or the view which, itself, is animating? Probably one or the other or both is the problem.

If the animation is supposed to run indefinitely, you are going to need to keep the view around indefinitely. And if it stops eventually, you should release it after it stops.


You call to addObject will fail when nil is passed. The UIImage could be nil when your system run out of memory and cannot allocate more. When that happens depends on how large your images are, but basically you can be sure that sooner of later use of loadingImageView.animationImages combined with allocating all your UIImage objects at the same time will cause your app to crash. See also playing-looping-images-sequence-in-uiview. You basically need a different approach that does not hold all the images in memory at the same time, the uncompressed images consume way too much memory.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号