Problem with UIImagePickerController

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

iphone
ios4
uiimagepickercontroller
presentmodalviewcontroller
asked on Stack Overflow Aug 20, 2010 by hiptomorrow

1 Answer

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.

answered on Stack Overflow Jun 15, 2011 by hiptomorrow

User contributions licensed under CC BY-SA 3.0