7

I have an application which work correctly with previous iOS versions, but then I tried run it on device with iOS7, application crashed sporadic. I tried to make a build with Xcode 5 which was recommended by Apple iOS7 GM SDK for upgrade existing apps, but the problem wasn't solved. I tried to research Apple documentation for AVCaptureSession, but also didn't found anything

my code is simple and standard

-(void)addVideoInput { 
    AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if (videoDevice) {
        NSError *error;
        self.videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
        if ([self.captureSession canAddInput:self.videoInput]) {
            [self.captureSession addInput:self.videoInput];
        }
    }
}

the app crashed in my function with next Stacktrace:

0 libobjc.A.dylib 0x395adb26 objc_msgSend + 5
1 AVFoundation 0x2e33a991 <redacted> + 348
2 AVFoundation 0x2e33aca1 <redacted> + 112
3 AVFoundation 0x2e33c4d1 <redacted> + 316
4 AVFoundation 0x2e33560f <redacted> + 354
5 AVFoundation 0x2e339bf1 <redacted> + 1436
6 Foundation 0x2fdbed31 <redacted> + 272
7 Foundation 0x2fdbe9d5 <redacted> + 344
8 Foundation 0x2fdaafed <redacted> + 88
9 AVFoundation 0x2e327483 <redacted> + 94
10 AVFoundation 0x2e33c505 <redacted> + 368
11 AVFoundation 0x2e3362c7 <redacted> + 906
12 myApp 0x00156159 -[CaptureManagerUniversal addVideoInput] + 540
13 myApp 0x00154cdf -[CaptureManagerUniversal init] + 2178
14 myApp 0x00077575 -[ViewFinderViewController didAppearActions] + 312
15 myApp 0x00077b11 -[ViewFinderViewController viewDidAppear:] + 128
16 UIKit 0x3199d43b <redacted> + 410
17 UIKit 0x3199d8bd <redacted> + 264
18 UIKit 0x31a4a4cb <redacted> + 870
19 UIKit 0x31a4a15b <redacted> + 274
20 UIKit 0x319bb417 <redacted> + 178
21 UIKit 0x319bb32f <redacted> + 70
22 QuartzCore 0x31613d99 <redacted> + 232
23 libdispatch.dylib 0x39ab1d67 <redacted> + 22
24 libdispatch.dylib 0x39ab87c1 <redacted> + 268
25 CoreFoundation 0x2f47a811 <redacted> + 8
26 CoreFoundation 0x2f4790e5 <redacted> + 1300
27 CoreFoundation 0x2f3e3cd7 CFRunLoopRunSpecific + 522
28 CoreFoundation 0x2f3e3abb CFRunLoopRunInMode + 106
29 GraphicsServices 0x33e602db GSEventRunModal + 138
30 UIKit 0x319e8121 UIApplicationMain + 1136
31 myApp 0x00097a9d main + 11 6
2
  • may be you are releasing an object that is already released (implicitly within the autorelease pool.. etc).
    – iPatel
    Sep 12, 2013 at 7:23
  • 1
    @iPatel you was right! I am used the Instruments for Zombies and result is: An Objective-C message was sent to a deallocated 'CaptureManagerUniversal' object (zombie) at address: 0x1568df30.. Thank You. I think iOS7 has multiple differences with previous version.
    – andproff
    Sep 14, 2013 at 12:46

1 Answer 1

10

I added to dealloc method in my custom CaptureManager:

[self.captureSession removeInput:self.videoInput];
[self.captureSession removeOutput:self.videoOutput];

before

self.captureSession = nil;
self.videoOutput = nil;
self.videoInput = nil;

and it is working for me (for iOS7 as well)

my dealloc method now is:

- (void)dealloc {
    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
    [notificationCenter removeObserver:[self deviceConnectedObserver]];
    [notificationCenter removeObserver:[self deviceDisconnectedObserver]];
    [notificationCenter removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

    [self.captureSession stopRunning];
    [self.captureSession removeInput:self.videoInput];
    [self.captureSession removeOutput:self.videoOutput];
    self.captureSession = nil;
    self.videoOutput = nil;
    self.videoInput = nil;
}
3
  • +1 For you, you solve my problem too. I got problem for AVCaptureVideoDataOutput. When i deallocate the camera class my app got crash on IOS7. After getting your answer, i also remove inputs and outputs added to session and now app is working fine on all IOS versions. Nov 29, 2013 at 12:17
  • I am pleased that this solution helped you :)
    – andproff
    Dec 4, 2013 at 20:27
  • fixed my problem too, i was totally clueless :)
    – mahmud
    May 5, 2014 at 5:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.