开发者

iPhone crash.. no console error

Update

I turned Zombies on... and got this error:

*** -[CALayer retain]: message sent to deallocated instance 0x709d1a0

I'm experiencing a crash that does not make any sense to me. In loadMediaList I'm programmatically creating multiple buttons and assigning an action(openMedia:) to them. That action has an "openURL" action. Everything works great, until the action is called; the action is performed, opened up in a new window, but then crashes once the app is exited. I replaced the "openURL" code with different code, and it still crashes... thoughts?

There is no error in the console, I get EXC_BAD_ACCESS. The console says:

sharedlibrary apply-load-rules all Current language: auto; currently objective-c kill quit Program ended with exit code: 0

I have been working on this issue for a few days now and I cannot figure it out. my dealloc is great, threads seem to be working well, etc. I don't know if this is legal on Stack Overflow, but I will gladly pay someone to help me solve this. I have a very tight deadline.

Hope you can help!

-(IBAction)showMedia:(id)sender {
    NSLog(@"Media Button was pressed");

    //Begin Alert
    [SVProgressHUD showInView:self.view status:@"Loading..."];

    mediaScroll.delegate = self;
    mediaScroll.frame = CGRectMake(15, 60, 240, 185);
    mediaScroll.clipsToBounds = YES;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.4];

    statsBTN.frame = CGRectMake(272, 76, 48, 46);
    donateBTN.frame = CGRectMake(272, 124, 48, 46);
    shareBTN.frame = CGRectMake(272, 172, 48, 46);
    mediaBTN.frame = CGRectMake(280, 220, 48, 46);

    incViewPopUP.alpha = 0;
    donViewPopUP.alpha = 0;
    shareViewPopUP.alpha = 0;
    mediaViewPopUP.alpha = 1;

    [UIView commitAnimations];

    [self loadMediaList];

    [mediaBTN addTarget:self action:@selector(closePopUp:) forControlEvents:UIControlEventTouchUpInside];
    }


-(void)loadMediaList {
[self.productPointers removeAllObjects];

    NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"date_reported" ascending:NO] autorelease];
    NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
    NSArray *sortedArray = [finalMediaList sortedArrayUsingDescriptors:sortDescriptors];
    NSLog(@"Sorted Media Array: %@", sortedArray);

    if (mediaLoaded == NO) {

        NSDictionary *mediaPost;
        for (mediaPost in sortedArray) {

            NSDictionary *inside = (NSDictionary *)[mediaPost valueForKey:@"media"];
            NSLog(@"Inside Array: %@", inside);

            UIButton *mediaView = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
            mediaView.frame = CGRectMake(0, (mx * 100), 225, 100);
            mediaView.backgroundColor = [UIColor clearColor];
            [mediaView addTarget:self action:@selector(openMedia:) forControlEvents:UIControlEventTouchUpInside];
            mediaView.titleLabel.hidden = YES;
            mediaView.titleLabel.alpha = 0;

            mx++; NSLog(@"MX: %i", mx);


            UILabel *mediaDesc = [[UILabel alloc] init];
            mediaDesc.frame = CGRectMake(50, 20, 154, 40);
            mediaDesc.backgroundColor = [UIColor clearColor];
            mediaDesc.font = [UIFont fontWithName:@"Geogrotesque" size:12];
            mediaDesc.textColor = UIColorFromRGB(0xc7c7c7);
            mediaDesc.numberOfLines = 0;
            mediaDesc.lineBreakMode = UILineBreakModeWordWrap;
            mediaDesc.text = [inside valueForKey:@"description"];

            UILabel *mediaType = [[UILabel alloc] init];
            mediaType.frame = CGRectMake(50, 40, 154, 50);
            mediaType.backgroundColor = [UIColor clearColor];
            mediaType.font = [UIFont fontWithName:@"Geogrotesque" size:12];
            mediaType.textColor = UIColorFromRGB(0xffffff);
            mediaType.numberOfLines = 0;
            mediaType.lineBreakMode = UILineBreakModeWordWrap;
            mediaType.text = [[inside valueForKey:@"type"] uppercaseString];


            UIImageView *mediaBorder = [[UIImageView alloc] initWithFrame:CGRectMake(0, 99.0, 220.0, 1.0)];
            [mediaBorder setImage:[UIImage imageNamed:@"bottom_border.png"]];

            UIImageView *mediaArrow = [[UIImageView alloc] initWithFrame:CGRectMake(214.0, 45.0, 6.0, 9.0)];
            [mediaArrow setImage:[UIImage imageNamed:@"media_right_arrow.png"]];


            if ([mediaType.text isEqualToString:@"VIDEO"]) {
                UIImageView *mediaThumb = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 35.0, 30.0, 30.0)] autorelease];
                [mediaThumb setImage:[UIImage imageNamed:@"media_play_icon.png"]];
                [mediaView addSubview:mediaThumb];
                [mediaThumb release];

                [mediaView setTag:1];
                [mediaView setTitle:[in开发者_运维百科side valueForKey:@"filename"] forState:UIControlStateNormal];
                }

            if ([mediaType.text isEqualToString:@"IMAGE"]) {
                UIImageView *mediaThumb = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 35.0, 30.0, 22.0)] autorelease];
                [mediaThumb setImage:[UIImage imageNamed:@"media_photo_icon.png"]];
                [mediaView addSubview:mediaThumb];
                [mediaThumb release];

                [mediaView setTag:2];
                [mediaView setTitle:[inside valueForKey:@"url"] forState:UIControlStateNormal];
                }


            [mediaView addSubview:mediaArrow];
            [mediaView addSubview:mediaBorder];
            [mediaView addSubview:mediaDesc];
            [mediaView addSubview:mediaType];
            [mediaScroll addSubview:mediaView];
            [self.productPointers addObject:mediaView];

            [mediaArrow release];
            [mediaBorder release];
            [mediaType release];
            [mediaDesc release];
            [mediaView release];
        }
    }

    mediaLoaded = YES;
    [mediaScroll setContentSize:CGSizeMake(225.0f, (mx * 100))];

    //End Alert
    [SVProgressHUD dismiss];
    }


-(IBAction)openMedia:(id)sender {
    NSLog(@"Media opened!");

    NSString *tag = [NSString stringWithFormat:@"%d", [sender tag]];
    NSLog(@"Tag: %@", tag);

    videoID = [sender currentTitle];

    NSString *videoURL = [[[NSString alloc] initWithFormat:@"http://www.vimeo.com/%@", videoID] autorelease];

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:videoURL]];
    NSLog(@"Video URL: %@", videoURL);
    }


Turn on malloc stack logging, guard malloc, and zombie enabled in the debugger, then run:

(gdb) info malloc-history 0x1b18b0

Where 0x1b18b0 is the address of the thing that has the bad access error. It should give you more info about where in your code the problem is.

See this article for better instructions


Also, some code thoughts that may help

change this:

videoID = [sender currentTitle];
NSString *videoURL = [[[NSString alloc] initWithFormat:@"http://www.vimeo.com/%@", videoID] autorelease];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:videoURL]];

To:

videoID = [sender currentTitle];
if (videoID) {
    // no need to alloc then set autorelease, just used a named initializer since they autorelease by default:
    NSString *videoURL = [NSString stringWithFormat:@"http://www.vimeo.com/%@", videoID];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:videoURL]];
} else {
    // deal
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜