iosipadcrashimagenamed

ipad 1 Crash - my app is bad somewhere


I have made an app, but on ipad 1 it crashes in the end part. On ipad-higher it remains working, but still I think I am doing something wrong, I really need to make something working more economically. But what is it?

In the end part it all happens. Before that, several screens are put onto each other and in the simulator when you go back they all are dismissed. But on the ipad 1 you will not even reach the end of the end part. I will try to explain what happens and several idea's about what is happening I have.

You can swipe on the screen and retina images (big images) are exchanged with the four corners that can get selected, each with a different image-background. There are six different scenes, so there are 6x4 + 6x1 for-normal-0-situation, 25 big retina images. There are only 5 frames working on top of each other (4 corners and 1 background), but I set inactive stuff to nil and load active images with imageNamed. It goes well on the simulator, but it crashes on the ipad 1, with no low memory warning or what so ever.

I've studied improvements: a) autorelease pool b) imageNamed replaced by imageContentsOfFile. The autorelease pools don't have any effect. imageNamed, I couldn't get imageContentsOfFile working, so I skipped the operation.

Any ideas of what is so excessively wrong and what kind of thoughts can be applied to have it work more economically, for it somewhere is demanding way too much in the end.

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint tappedPt = [[touches anyObject] locationInView:self.view];

NSArray *subviews = [[NSArray alloc]init];

subviews = [self.view subviews];

// Return if there are no subviews
if ([subviews count] == 0) return;

for (UIView *subview in subviews) {
    if ([subview pointInside:[self.view convertPoint:tappedPt toView:subview]    withEvent:event]){

        [self checkAndChange:subview];

        [self modifyChoice:subview];
    }
}
}


- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// Get the subviews of the view

CGPoint tappedPt = [[touches anyObject] locationInView:self.view];

NSArray *subviews = [[NSArray alloc]init];

subviews = [self.view subviews];

// Return if there are no subviews
if ([subviews count] == 0) return;

for (UIView *subview in subviews) {

    if ([subview pointInside:[self.view convertPoint:tappedPt toView:subview] withEvent:event]){

        [self checkAndChange:subview];

        [self modifyChoice:subview];

    }

}

}

-(void) modifyChoice:(UIView *)subview
{
if(subview==area1LinksBoven){[gekozenExpressieBijDimensie replaceObjectAtIndex:dimensie-1 withObject:[NSNumber numberWithInteger:1]];}
if(subview==area2RechtsBoven){[gekozenExpressieBijDimensie replaceObjectAtIndex:dimensie-1 withObject:[NSNumber numberWithInteger:2]];}
if(subview==area3RechtsOnder){[gekozenExpressieBijDimensie replaceObjectAtIndex:dimensie-1 withObject:[NSNumber numberWithInteger:3]];}
if(subview==area4LinksOnder){[gekozenExpressieBijDimensie replaceObjectAtIndex:dimensie-1 withObject:[NSNumber numberWithInteger:4]];}

if(maxChoice<dimensie){maxChoice=dimensie;
    if(maxChoice==1){headerGevuld.image = [UIImage imageNamed:@"TOP1.png"];}
    if(maxChoice==2){headerGevuld.image = [UIImage imageNamed:@"TOP2.png"];}
    if(maxChoice==3){headerGevuld.image = [UIImage imageNamed:@"TOP3.png"];}
    if(maxChoice==4){headerGevuld.image = [UIImage imageNamed:@"TOP4.png"];}
    if(maxChoice==5){headerGevuld.image = [UIImage imageNamed:@"TOP5.png"];}
    if(maxChoice==6){headerGevuld.image = [UIImage imageNamed:@"TOP6.png"];}
}
}

-(void) checkAndChange:(UIView *)subview{

if(subview==area1LinksBoven){
    area1LinksBoven.image = [UIImage imageNamed:@"SELECTION1.png"];
    area2RechtsBoven.image = nil;
    area3RechtsOnder.image = nil;
    area4LinksOnder.image = nil;
    footer.image = [UIImage imageNamed:@"FOOT1.png"];
    @autoreleasepool {
    if(dimensie==1){
        filmAchtergrond0.image = [UIImage imageNamed:@"1PassiefActiefOntspanning.jpg"];}
    if(dimensie==2){
        filmAchtergrond0.image = [UIImage imageNamed:@"1MakkelijkMoeilijkMaster.jpg"];}
    if(dimensie==3){
        filmAchtergrond0.image = [UIImage imageNamed:@"1VeiligGevaarlijkGeborgenheid.jpg"];}
    if(dimensie==4){filmAchtergrond0.image = [UIImage imageNamed:@"1NormaalBijzonderGeaard.jpg"];}
    if(dimensie==5){filmAchtergrond0.image = [UIImage imageNamed:@"1AlleenSamenUniek.jpg"];}
    if(dimensie==6){filmAchtergrond0.image = [UIImage imageNamed:@"1OrdeChaosDuidelijk.jpg"];}
    }
    [arrowRight setImage:[UIImage imageNamed:@"ARROW_RIGHT_ACTIVE.png"] forState:UIControlStateNormal];
}
if(subview==area2RechtsBoven){
    area1LinksBoven.image = nil;
    area2RechtsBoven.image = [UIImage imageNamed:@"SELECTION2.png"];
    area3RechtsOnder.image = nil;
    area4LinksOnder.image = nil;
    footer.image = [UIImage imageNamed:@"FOOT2.png"];
    @autoreleasepool {        
    if(dimensie==1){filmAchtergrond0.image = [UIImage imageNamed:@"2PassiefActiefEnergiek.jpg"];}
    if(dimensie==2){
        filmAchtergrond0.image = [UIImage imageNamed:@"2MakkelijkMoeilijkUitdagend.jpg"];}
    if(dimensie==3){
        filmAchtergrond0.image = [UIImage imageNamed:@"2VeiligGevaarlijkSpannend.jpg"];}
    if(dimensie==4){filmAchtergrond0.image = [UIImage imageNamed:@"2NormaalBijzonderWow.jpg"];}
    if(dimensie==5){filmAchtergrond0.image = [UIImage imageNamed:@"2AlleenSamenGezellig.jpg"];}
    if(dimensie==6){filmAchtergrond0.image = [UIImage imageNamed:@"2OrdeChaosImproviseren.jpg"];}
    }
    [arrowRight setImage:[UIImage imageNamed:@"ARROW_RIGHT_ACTIVE.png"] forState:UIControlStateNormal];
}
if(subview==area3RechtsOnder){
    area1LinksBoven.image = nil;
    area2RechtsBoven.image = nil;
    area3RechtsOnder.image = [UIImage imageNamed:@"SELECTION3.png"];
    area4LinksOnder.image = nil;
    footer.image = [UIImage imageNamed:@"FOOT3.png"];
    @autoreleasepool {
    if(dimensie==1){
        filmAchtergrond0.image = [UIImage imageNamed:@"3PassiefActiefUitputting.jpg"];}
    if(dimensie==2){
        filmAchtergrond0.image = [UIImage imageNamed:@"3MakkelijkMoeilijkFrustrerend.jpg"];}
    if(dimensie==3){
        filmAchtergrond0.image = [UIImage imageNamed:@"3VeiligGevaarlijkGevaarlijk.jpg"];}
    if(dimensie==4){
        filmAchtergrond0.image = [UIImage imageNamed:@"3NormaalBijzonderOnbegrijjpelijk.jpg"];}
    if(dimensie==5){filmAchtergrond0.image = [UIImage imageNamed:@"3AlleenSamenGroepsdruk.jpg"];}
    if(dimensie==6){filmAchtergrond0.image = [UIImage imageNamed:@"3OrdeChaosRommeltje.jpg"];}
    }
    [arrowRight setImage:[UIImage imageNamed:@"ARROW_RIGHT_ACTIVE.png"] forState:UIControlStateNormal];
}
if(subview==area4LinksOnder){
    area1LinksBoven.image = nil;
    area2RechtsBoven.image = nil;
    area3RechtsOnder.image = nil;
    area4LinksOnder.image = [UIImage imageNamed:@"SELECTION4.png"];
    footer.image = [UIImage imageNamed:@"FOOT4.png"];
    @autoreleasepool {
    if(dimensie==1){filmAchtergrond0.image = [UIImage imageNamed:@"4PassiefActiefApathie.jpg"];}
    if(dimensie==2){filmAchtergrond0.image = [UIImage imageNamed:@"4MakkelijkMoeilijkSaai.jpg"];}
    if(dimensie==3){
        filmAchtergrond0.image = [UIImage imageNamed:@"4VeiligGevaarlijkBeklemmend.jpg"];}
    if(dimensie==4){filmAchtergrond0.image = [UIImage imageNamed:@"4NormaalBijzonderSleur.jpg"];}
    if(dimensie==5){filmAchtergrond0.image = [UIImage imageNamed:@"4AlleenSamenEenzaam.jpg"];}
    if(dimensie==6){filmAchtergrond0.image = [UIImage imageNamed:@"4OrdeChaosRigide.jpg"];}
    }
    [arrowRight setImage:[UIImage imageNamed:@"ARROW_RIGHT_ACTIVE.png"] forState:UIControlStateNormal];
}

if(dimensie==1){headerPositie.image = [UIImage imageNamed:@"OUT1.png"];}
if(dimensie==2){headerPositie.image = [UIImage imageNamed:@"OUT2.png"];}
if(dimensie==3){headerPositie.image = [UIImage imageNamed:@"OUT3.png"];}
if(dimensie==4){headerPositie.image = [UIImage imageNamed:@"OUT4.png"];}
if(dimensie==5){headerPositie.image = [UIImage imageNamed:@"OUT5.png"];}
if(dimensie==6){headerPositie.image = [UIImage imageNamed:@"OUT6.png"];}
}

Solution

  • Load the images using UIImage imageWithContentsOfFile:

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"fileExtension"]; 
    UIImage *img = [UIImage imageWithContentsOfFile:filePath];
    

    See here the difference between imageNamed and imageWithContentsOfFile:
    http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference.html