1

I'm having a problem with the UIImagePickerController being presented with presentModalViewController. As soon as the view displays (be it camera or photo album), the app crashes.

The whole UI is created in code, no interface builder. This has only stopped working since I've been updating the code to run on ios4. Using leaks, I can't find any, and the total memory allocation I'm getting is around 5mb.

Here's the code that I'm using to present the camera picker -

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
[imagePicker setAllowsEditing:YES];
[imagePicker setCameraCaptureMode:UIImagePickerControllerCameraCaptureModePhoto];
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];

And the delegates as follows -

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
  UIImage *selectedImage = [info objectForKey:UIImagePickerControllerEditedImage];
  UIImage *newImage = [self createGameImage:selectedImage];
  [gameOptionsImageDisplay setImage:[self resizeImage:newImage toSize:CGSizeMake(95, 95)]];  
  [self dismissModalViewControllerAnimated:YES];
  [mainView setFrame:CGRectMake(0, 0, 320, 480)]; 
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
  [self dismissModalViewControllerAnimated:YES];
  [mainView setFrame:CGRectMake(0, 0, 320, 480)];  
}

Setting NSZombiesEnabled to YES is telling me -

*** -[UIImage isKindOfClass:]: message sent to deallocated instance 0x142fc0

And the stack trace is as follows -

0 0x313f7d7c in ___forwarding___
1 0x3138a680 in __forwarding_prep_0___
2 0x3166dad2 in -[UIImageView(UIImageViewInternal) _canDrawContent]
3 0x3166c652 in -[UIView(Internal) _didMoveFromWindow:toWindow:]
4 0x3166c50e in -[UIView(Internal) _didMoveFromWindow:toWindow:]
5 0x3166c50e in -[UIView(Internal) _didMoveFromWindow:toWindow:]
6 0x3166c50e in -[UIView(Internal) _didMoveFromWindow:toWindow:]
7 0x3166c50e in -[UIView(Internal) _didMoveFromWindow:toWindow:]
8 0x3166aa8a in -[UIView(Hierarchy) _postMovedFromSuperview:]
9 0x31672df6 in -[UIView(Hierarchy) removeFromSuperview]
10 0x316d76ee in -[UITransitionView _didCompleteTransition:]
11 0x31754556 in -[UITransitionView _transitionDidStop:finished:]
12 0x316bc97a in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
13 0x316bc884 in -[UIViewAnimationState animationDidStop:finished:]
14 0x33e487c0 in run_animation_callbacks
15 0x33e48662 in CA::timer_callback
16 0x313caa5a in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
17 0x313ccee4 in __CFRunLoopDoTimer
18 0x313cd864 in __CFRunLoopRun
19 0x313768ea in CFRunLoopRunSpecific
20 0x313767f2 in CFRunLoopRunInMode
21 0x329f36ee in GSEventRunModal
22 0x329f379a in GSEventRun
23 0x316692a6 in -[UIApplication _run]
24 0x31667e16 in UIApplicationMain
25 0x00002726 in main at main.m:14

If anybody can help me out here, I would be eternally grateful!

Thanks,

Stewart

5
  • I'd like to know a little more about your view controller. There's a UIImage that looks like it's being double released... are there any UIImage properties in your view controller? Also, I'm sure you've handled this, and it would lead to a different error message, but you are aware that you cannot use the camera on the simulator? Best to test for the user's capabilities, otherwise it will generate an exception on an iPod Touch. Also, can you confirm via breakpoints that the code never gets as far as your delegate callbacks? Commented Aug 20, 2010 at 0:57
  • 1
    I think the problem is in the parent UIViewController. You say you create it programmatically. Can you show the code? Commented Aug 20, 2010 at 1:06
  • @phooze - Yeah, I'm testing whether or not there's a camera available before the option is displayed and that works fine. @St3fan - The code which is calling the picker is a subclass of UIViewController, and it's created in the app delegate and added to the window. I've since replaced the image picker with a new UIViewController with a single UIView in it with a nice red background colour and while the view displays on presentModalViewController, it still crashes as soon as it's completed presenting in the window. BAH! Commented Aug 20, 2010 at 11:21
  • Stewart, thanks for the details. Also want to see your UIViewController subclass code as well. Commented Aug 23, 2010 at 6:29
  • Problem solved. After going through my view controller code and trial and error with releasing objects, I finally found the culprit, but that leads me to a question... Is loadView called when a modal view is presented on top? – Stewart Zollinger 0 secs ago edit Commented Aug 24, 2010 at 20:16

1 Answer 1

2

I was releasing an image that was also being autoreleased. On the odd occasion, the code would work, but most of the time it was falling down. In 3.2, this hadn't caused me any errors or shown up, so the chances are it wasn't being autoreleased while I was still needing it. Lots of trial and error found it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.