EXC_BAD_ACCESS when I change moviePlayer contentURL

Posted by Bruno on Stack Overflow See other posts from Stack Overflow or by Bruno
Published on 2010-12-22T17:45:00Z Indexed on 2010/12/23 8:54 UTC
Read the original article Hit count: 274

Hello,

In few words, my application is doing that :

1) My main view (MovieListController) has some video thumbnails and when I tap on one, it displays the moviePlayer (MoviePlayerViewController) :

MovieListController.h :

@interface MoviePlayerViewController : UIViewController <UITableViewDelegate>{
    UIView *viewForMovie;
    MPMoviePlayerController *player;
}

@property (nonatomic, retain) IBOutlet UIView *viewForMovie;
@property (nonatomic, retain) MPMoviePlayerController *player;

- (NSURL *)movieURL;

@end

MovieListController.m :

 MoviePlayerViewController *controllerTV = [[MoviePlayerViewController alloc] initWithNibName:@"MoviePlayerViewController" bundle:nil];
 controllerTV.delegate = self;
 controllerTV.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
 [self presentModalViewController: controllerTV animated: YES];
 [controllerTV release];

2) In my moviePlayer, I initialize the video I want to play

MoviePlayerViewController.m :

@implementation MoviePlayerViewController
@synthesize player;
@synthesize viewForMovie;

- (void)viewDidLoad {

  NSLog(@"start");
  [super viewDidLoad];
  self.player = [[MPMoviePlayerController alloc] init];
  self.player.view.frame = self.viewForMovie.bounds;
  self.player.view.autoresizingMask = 
  UIViewAutoresizingFlexibleWidth |
  UIViewAutoresizingFlexibleHeight;
  [self.viewForMovie addSubview:player.view];
  self.player.contentURL = [self movieURL];
    }

    - (void)dealloc {
     NSLog(@"dealloc TV");
     [player release];
     [viewForMovie release];
        [super dealloc];
    }

     -(NSURL *)movieURL
    {
     NSBundle *bundle = [NSBundle mainBundle];
      NSString *moviePath = 
      [bundle 
       pathForResource:@"FR_Tribord_Surf camp_100204" 
       ofType:@"mp4"];
      if (moviePath) {
       return [NSURL fileURLWithPath:moviePath];
      } else {
      return nil;
      }
     }

-> It's working good, my movie is display

My problem :

When I go back to my main view :

- (void) returnToMap: (MoviePlayerViewController *) controller {

 [self dismissModalViewControllerAnimated: YES];
}

And I tap in a thumbnail to display again the moviePlayer (MoviePlayerViewController), I get a *Program received signal: “EXC_BAD_ACCESS”.*

In my debugger I saw that it's stopping on the thread "main" :

//
//  main.m
//  MoviePlayer
//
//  Created by Eric Freeman on 3/27/10.
//  Copyright Apple Inc 2010. All rights reserved.
//

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil); //EXC_BAD_ACCESS
    [pool release];
    return retVal;
}

If I comment self.player.contentURL = [self movieURL]; it's working, but when I let it, iI have this problem.

I read that it's due to null pointer or memory problem but I don't understand why it's working the first time and not the second time. I release my object in dealloc method.

Thanks for your help !

Bruno.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about memory-leaks