I am using static library "libWebRTC.a" to create IOS App by binding it using Xamarin binding.
when I call _factory.VideoSourceWithCapturer(capturer, mediaConstraints); in this code the application crashes
RTCVideoTrack CreateLocalVideoTrack()
{
RTCVideoTrack localVideoTrack = null;
AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, (bool isAccessGranted) =>
{
if (isAccessGranted)
{
String cameraID = "";
for (int i = 0; i < AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video).Length; i++)
{
if (AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video)[i].Position == AVCaptureDevicePosition.Front)
{
cameraID = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video)[i].LocalizedName;
break;
}
}
//do something
RTCVideoCapturer capturer = RTCVideoCapturer.CapturerWithDeviceName(cameraID);
RTCMediaConstraints mediaConstraints = DefaultMediaStreamConstraints();
RTCVideoSource videoSource = _factory.VideoSourceWithCapturer(capturer, mediaConstraints);
localVideoTrack = _factory.VideoTrackWithID(#"ARDAMSv0", videoSource);
}
else
{
}
});
return localVideoTrack;
}
and this is the message :
Native stacktrace:
critical: 0 libmonosgen-2.0.dylib 0x0000000100a18184 mono_handle_native_sigsegv + 260
critical: 1 libmonosgen-2.0.dylib 0x0000000100a23618 mono_sigsegv_signal_handler + 220
critical: 2 libsystem_platform.dylib 0x0000000185a08348 _sigtramp + 52
critical: 3 TestRTC 0x000000010020b1fc _ZN7cricket13VideoCapturer15SetCaptureStateENS_12CaptureStateE + 52
critical: 4 TestRTC 0x0000000100214764 _ZN7cricket19WebRtcVideoCapturer5StartERKNS_11VideoFormatE + 1084
critical: 5 TestRTC 0x000000010020b190 _ZN7cricket13VideoCapturer14StartCapturingERKNS_11VideoFormatE + 52
critical: 6 TestRTC 0x0000000100202020 _ZN7cricket14CaptureManager26StartWithBestCaptureFormatEPNS_18VideoCapturerStateEPNS_13Vi
deoCapturerE + 204
critical: 7 TestRTC 0x0000000100201ea0 _ZN7cricket14CaptureManager17StartVideoCaptureEPNS_13VideoCapturerERKNS_11VideoFormatE + 196
critical: 8 TestRTC 0x000000010028c658 _ZN3rtc21FunctorMessageHandlerIbNS_14MethodFunctor2IN7cricket14CaptureManagerEMS3_FbPNS2_13VideoCapturerERKNS2_11VideoFormatEEbS5_S8_EEE9OnMessageEPNS_7MessageE + 24
critical: 9 TestRTC 0x00000001001f10c4 ZN3rtc6Thread22ReceiveSendsFromThreadEPKS0 + 116
critical: 10 TestRTC 0x00000001001dc338 _ZN3rtc12MessageQueue3GetEPNS_7MessageEib + 156
critical: 11 TestRTC 0x00000001001f0df0 _ZN3rtc6Thread15ProcessMessagesEi + 108
TestRTC[634:2
Related
I am seeing a crash in AppDelegate. I believe it is related to a song ending just as I go to make an in-app purchase or possibly the sound effect that I play when an in-app purchase completes (sort of a coin sound), as it happens occasionally but not frequently.
The crash log (below below) points to this in particular as the last thing called before the crash:
4 SpriteKit 0x233882e3c -[SKSoundSource purgeCompletedBuffers] + 155
I handle stopping and starting audio with code as follows:
func applicationWillResignActive(_ application: UIApplication)
{
// Nil out the system clock variables
if GameData.sharedInstance.isValidSystemClock != nil && GameData.sharedInstance.isValidSystemClock!
{
GameData.sharedInstance.isValidSystemClock = nil
}
GameData.sharedInstance.currentServerTime = nil
// Capture the last time the user was in the app, so we can catch if they rewind their system clock while offline
GameData.sharedInstance.timeOfLastAppLaunch = CFAbsoluteTimeGetCurrent()
// Save game data to file
GameData.sharedInstance.saveGameToFile()
//schedule notifications for user to come back soon!
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "scheduleNotificationFreeChest"), object: nil)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "scheduleNotificationReminders"), object: nil)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "scheduleNotificationLivesFull"), object: nil)
//pause background music if it's playing
if AssetsSounds.sharedInstance.bgmTitlePlayer?.isPlaying ?? false
{
AssetsSounds.sharedInstance.bgmTitlePlayer?.pause()
needToPlayTitleMusic = true
}
//pause game music if it's playing
if AssetsSounds.sharedInstance.bgmGamePlayer?.isPlaying ?? false
{
AssetsSounds.sharedInstance.bgmGamePlayer?.pause()
needToPlayGameMusic = true
}
if AssetsSounds.sharedInstance.bgmBonusLoop?.isPlaying ?? false
{
AssetsSounds.sharedInstance.bgmBonusLoop?.pause()
needToPlayBonusLoop = true
}
if AssetsSounds.sharedInstance.bgmBonusLeadIn?.isPlaying ?? false
{
AssetsSounds.sharedInstance.bgmBonusLeadIn?.pause()
needToPlayBonusLeadIn = true
}
if AssetsSounds.sharedInstance.bgmFiveMovesLeft?.isPlaying ?? false
{
AssetsSounds.sharedInstance.bgmFiveMovesLeft?.pause()
needToPlayFiveMovesLeft = true
}
if AssetsSounds.sharedInstance.bgmRainWithBirds?.isPlaying ?? false
{
AssetsSounds.sharedInstance.bgmRainWithBirds?.pause()
needToPlayRainWithBirds = true
}
}
And, upon return from the interruption:
func applicationDidBecomeActive(_ application: UIApplication)
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
// kill notifications scheduled since user is back
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
// Clears app badge number; we put a 1 when we send a notification
UIApplication.shared.applicationIconBadgeNumber = 0
if AVAudioSession.sharedInstance().secondaryAudioShouldBeSilencedHint
{
AssetsSounds.sharedInstance.bgmGamePlayer?.stop()
AssetsSounds.sharedInstance.bgmGamePlayer = nil
needToPlayGameMusic = false
AssetsSounds.sharedInstance.bgmTitlePlayer?.stop()
AssetsSounds.sharedInstance.bgmTitlePlayer = nil
needToPlayTitleMusic = false
AssetsSounds.sharedInstance.bgmBonusLeadIn?.stop()
AssetsSounds.sharedInstance.bgmBonusLeadIn = nil
needToPlayBonusLeadIn = false
AssetsSounds.sharedInstance.bgmBonusLoop?.stop()
AssetsSounds.sharedInstance.bgmBonusLoop = nil
needToPlayBonusLoop = false
AssetsSounds.sharedInstance.bgmFiveMovesLeft?.stop()
AssetsSounds.sharedInstance.bgmFiveMovesLeft = nil
needToPlayFiveMovesLeft = false
AssetsSounds.sharedInstance.bgmRainWithBirds?.stop()
AssetsSounds.sharedInstance.bgmRainWithBirds = nil
needToPlayRainWithBirds = false
}
else if needToPlayGameMusic || needToPlayTitleMusic || needToPlayRainWithBirds || needToPlayBonusLoop || needToPlayBonusLeadIn || needToPlayFiveMovesLeft
{
//play background music if it needs to be played
if needToPlayTitleMusic
{
AssetsSounds.sharedInstance.bgmTitlePlayer?.play()
needToPlayTitleMusic = false
}
//play game music if it needs to be played
if needToPlayGameMusic
{
AssetsSounds.sharedInstance.bgmGamePlayer?.play()
needToPlayGameMusic = false
}
if needToPlayBonusLoop
{
AssetsSounds.sharedInstance.bgmBonusLoop?.play()
needToPlayBonusLoop = false
}
if needToPlayBonusLeadIn
{
AssetsSounds.sharedInstance.bgmBonusLeadIn?.play()
needToPlayBonusLeadIn = false
}
if needToPlayFiveMovesLeft
{
AssetsSounds.sharedInstance.bgmFiveMovesLeft?.play()
needToPlayFiveMovesLeft = false
}
if needToPlayRainWithBirds
{
AssetsSounds.sharedInstance.bgmRainWithBirds?.play()
needToPlayRainWithBirds = false
}
} // end else if
else
{
if viewController.mapScreen != nil
{
AssetsSounds.sharedInstance.bgmTitlePlayer = AssetsSounds.sharedInstance.loadAudioPlayer(SongType.title1, loops: 0)
AssetsSounds.sharedInstance.bgmTitlePlayer?.play()
}
else if viewController.scene != nil && viewController.gameState != .gameover && viewController.gameState != .lost && viewController.gameState != .won && viewController.level != nil && viewController.level.songType != nil
{
AssetsSounds.sharedInstance.bgmGamePlayer = AssetsSounds.sharedInstance.loadAudioPlayer(viewController.level.songType!, loops: 0)
AssetsSounds.sharedInstance.bgmGamePlayer?.play()
viewController.scene.addMusicCredits()
} // end else if
}
}
Have others seen similar crashes related to sound / interruptions? What is the proper way to handle this?
I have seen another post: Sprite Kit & playing sound leads to app termination that references this, but I am not sure if my issue is the same or if the answer here is valid.
Below is the symbolic crash log from my phone:
OS Version: iPhone OS 12.3.1 (16F203)
Baseband Version: 3.60.01
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Application Specific Information:
abort() called
Last Exception Backtrace:
0 CoreFoundation 0x21cb4927c __exceptionPreprocess + 228
1 libobjc.A.dylib 0x21bd239f8 objc_exception_throw + 55
2 CoreFoundation 0x21cac2ce8 _CFThrowFormattedException + 111
3 CoreFoundation 0x21ca34298 -[__NSArrayM removeObjectsInRange:] + 2235
4 SpriteKit 0x233882e3c -[SKSoundSource purgeCompletedBuffers] + 155
5 SpriteKit 0x2338830d4 -[SKSoundSource dealloc] + 47
6 CoreFoundation 0x21caa9ed4 cow_cleanup + 111
7 CoreFoundation 0x21ca334d4 -[__NSArrayM dealloc] + 67
8 SpriteKit 0x233883434 SKCRendererRemoveCompletedSoundSources+ 836660 () + 331
9 SpriteKit 0x2337f12d0 -[SKScene _update:] + 751
10 SpriteKit 0x233816114 -[SKView _update:] + 835
11 SpriteKit 0x2338117f4 __51-[SKView _vsyncRenderForTime:preRender:postRender:]_block_invoke.351 + 387
12 SpriteKit 0x233810bf8 -[SKView _vsyncRenderForTime:preRender:postRender:] + 519
13 SpriteKit 0x233813c54 __29-[SKView setUpRenderCallback]_block_invoke + 207
14 SpriteKit 0x233856c18 -[SKDisplayLink _callbackForNextFrame:] + 163
15 QuartzCore 0x220ed0f90 CA::Display::DisplayLink::dispatch_items+ 69520 (unsigned long long, unsigned long long, unsigned long long) + 635
16 QuartzCore 0x220f9ab10 display_timer_callback+ 895760 (__CFMachPort*, void*, long, void*) + 271
17 CoreFoundation 0x21cab4a8c __CFMachPortPerform + 187
18 CoreFoundation 0x21cadb690 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 55
19 CoreFoundation 0x21cadaddc __CFRunLoopDoSource1 + 439
20 CoreFoundation 0x21cad5c00 __CFRunLoopRun + 2095
21 CoreFoundation 0x21cad50b0 CFRunLoopRunSpecific + 435
22 GraphicsServices 0x21ecd579c GSEventRunModal + 103
23 UIKitCore 0x249341978 UIApplicationMain + 211
24 Pandamonium! 0x100bdd8ec main + 22764 (AppDelegate.swift:19)
25 libdyld.dylib 0x21c59a8e0 start + 3
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x000000021c6e60dc __pthread_kill + 8
1 libsystem_pthread.dylib 0x000000021c7639b0 pthread_kill$VARIANT$armv81 + 296
2 libsystem_c.dylib 0x000000021c63fea8 abort + 140
3 libc++abi.dylib 0x000000021bd0c788 __cxa_bad_cast + 0
4 libc++abi.dylib 0x000000021bd0c934 default_unexpected_handler+ 6452 () + 0
5 libobjc.A.dylib 0x000000021bd23e00 _objc_terminate+ 24064 () + 124
6 libc++abi.dylib 0x000000021bd18838 std::__terminate(void (*)+ 55352 ()) + 16
7 libc++abi.dylib 0x000000021bd18434 __cxa_rethrow + 144
8 libobjc.A.dylib 0x000000021bd23bc8 objc_exception_rethrow + 44
9 CoreFoundation 0x000000021cad511c CFRunLoopRunSpecific + 544
10 GraphicsServices 0x000000021ecd579c GSEventRunModal + 104
11 UIKitCore 0x0000000249341978 UIApplicationMain + 212
12 Pandamonium! 0x0000000100bdd8ec main + 22764 (AppDelegate.swift:19)
13 libdyld.dylib 0x000000021c59a8e0 start + 4
Thread 1 name: com.apple.uikit.eventfetch-thread
Thread 1:
0 libsystem_kernel.dylib 0x000000021c6db0f4 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000021c6da5a0 mach_msg + 72
2 CoreFoundation 0x000000021cadaa10 __CFRunLoopServiceMachPort + 236
3 CoreFoundation 0x000000021cad5920 __CFRunLoopRun + 1360
4 CoreFoundation 0x000000021cad50b0 CFRunLoopRunSpecific + 436
5 Foundation 0x000000021d4a2fac -[NSRunLoop+ 32684 (NSRunLoop) runMode:beforeDate:] + 300
6 Foundation 0x000000021d4a2e3c -[NSRunLoop+ 32316 (NSRunLoop) runUntilDate:] + 96
7 UIKitCore 0x0000000249427494 -[UIEventFetcher threadMain] + 136
8 Foundation 0x000000021d5cf6a4 __NSThread__start__ + 984
9 libsystem_pthread.dylib 0x000000021c7682c0 _pthread_body + 128
10 libsystem_pthread.dylib 0x000000021c768220 _pthread_start + 44
11 libsystem_pthread.dylib 0x000000021c76bcdc thread_start + 4
Thread 2 name: AVAudioSession Notify Thread
Thread 2:
0 libsystem_kernel.dylib 0x000000021c6db0f4 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000021c6da5a0 mach_msg + 72
2 CoreFoundation 0x000000021cadaa10 __CFRunLoopServiceMachPort + 236
3 CoreFoundation 0x000000021cad5920 __CFRunLoopRun + 1360
4 CoreFoundation 0x000000021cad50b0 CFRunLoopRunSpecific + 436
5 AVFAudio 0x00000002229bd334 GenericRunLoopThread::Entry+ 574260 (void*) + 156
6 AVFAudio 0x00000002229e7c60 CAPThread::Entry+ 748640 (CAPThread*) + 88
7 libsystem_pthread.dylib 0x000000021c7682c0 _pthread_body + 128
8 libsystem_pthread.dylib 0x000000021c768220 _pthread_start + 44
9 libsystem_pthread.dylib 0x000000021c76bcdc thread_start + 4
Thread 3 name: com.apple.NSURLConnectionLoader
Thread 3:
0 libsystem_kernel.dylib 0x000000021c6db0f4 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000021c6da5a0 mach_msg + 72
2 CoreFoundation 0x000000021cadaa10 __CFRunLoopServiceMachPort + 236
3 CoreFoundation 0x000000021cad5920 __CFRunLoopRun + 1360
4 CoreFoundation 0x000000021cad50b0 CFRunLoopRunSpecific + 436
5 CFNetwork 0x000000021d0ee74c -[__CoreSchedulingSetRunnable runForever] + 216
6 Foundation 0x000000021d5cf6a4 __NSThread__start__ + 984
7 libsystem_pthread.dylib 0x000000021c7682c0 _pthread_body + 128
8 libsystem_pthread.dylib 0x000000021c768220 _pthread_start + 44
9 libsystem_pthread.dylib 0x000000021c76bcdc thread_start + 4
Thread 4 name: com.apple.coreaudio.AQClient
Thread 4:
0 libsystem_kernel.dylib 0x000000021c6db0f4 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000021c6da5a0 mach_msg + 72
2 CoreFoundation 0x000000021cadaa10 __CFRunLoopServiceMachPort + 236
3 CoreFoundation 0x000000021cad5920 __CFRunLoopRun + 1360
4 CoreFoundation 0x000000021cad50b0 CFRunLoopRunSpecific + 436
5 AudioToolbox 0x0000000220b527d8 GenericRunLoopThread::Entry+ 2299864 (void*) + 156
6 AudioToolbox 0x0000000220de14f8 CAPThread::Entry+ 4982008 (CAPThread*) + 88
7 libsystem_pthread.dylib 0x000000021c7682c0 _pthread_body + 128
8 libsystem_pthread.dylib 0x000000021c768220 _pthread_start + 44
9 libsystem_pthread.dylib 0x000000021c76bcdc thread_start + 4
Thread 5 name: com.squareup.SocketRocket.NetworkThread
Thread 5:
0 libsystem_kernel.dylib 0x000000021c6db0f4 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000021c6da5a0 mach_msg + 72
2 CoreFoundation 0x000000021cadaa10 __CFRunLoopServiceMachPort + 236
3 CoreFoundation 0x000000021cad5920 __CFRunLoopRun + 1360
4 CoreFoundation 0x000000021cad50b0 CFRunLoopRunSpecific + 436
5 Foundation 0x000000021d4a2fac -[NSRunLoop+ 32684 (NSRunLoop) runMode:beforeDate:] + 300
6 Pandamonium! 0x0000000100f08d4c -[_FSRRunLoopThread main] + 3345740 (FSRWebSocket.m:1843)
7 Foundation 0x000000021d5cf6a4 __NSThread__start__ + 984
8 libsystem_pthread.dylib 0x000000021c7682c0 _pthread_body + 128
9 libsystem_pthread.dylib 0x000000021c768220 _pthread_start + 44
10 libsystem_pthread.dylib 0x000000021c76bcdc thread_start + 4
Thread 6 name: com.apple.CFSocket.private
Thread 6:
0 libsystem_kernel.dylib 0x000000021c6e6328 __select + 8
1 CoreFoundation 0x000000021cae36f4 __CFSocketManager + 620
2 libsystem_pthread.dylib 0x000000021c7682c0 _pthread_body + 128
3 libsystem_pthread.dylib 0x000000021c768220 _pthread_start + 44
4 libsystem_pthread.dylib 0x000000021c76bcdc thread_start + 4
Thread 7:
0 libsystem_pthread.dylib 0x000000021c76bcd0 start_wqthread + 0
Thread 8:
0 libsystem_pthread.dylib 0x000000021c76bcd0 start_wqthread + 0
Thread 9:
0 libsystem_pthread.dylib 0x000000021c76bcd0 start_wqthread + 0
Thread 10:
0 libsystem_pthread.dylib 0x000000021c76bcd0 start_wqthread + 0
I'm checking self.next_id is not null why would this line crash? I can't reproduce the issue on my test devices. I only get crash reports from Crashlytics at this line.
-(Second*)getNextSecond:(BOOL)returnSelf{
Second* retValue = nil;
if(self.next_id){
//this line !!!!
retValue = [[SecondDatabase sharedManager] getSecond:[self.next_id stringValue]];
}
if (retValue == nil && returnSelf) {
return self;
}else{
return retValue;
}
}
This is my SecondDatabase sharedManager function:
#property NSMutableDictionary* dictionary;
- (id)init {
if (self = [super init]) {
_dictionary = [#{} mutableCopy];
}
return self;
}
+ (id)sharedManager {
static SecondDatabase *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
This is my getSecond function:
-(Second*)getSecond:(NSString*)idString{
return [_dictionary objectForKey:idString];
}
Where should I be investigating? Would this crash if dictionary didn't have object for key so that it returns NULL?
My crash report:
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x000007d8
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x3acd164c realizeClass(objc_class*) + 19
1 libobjc.A.dylib 0x3acd1715 realizeClass(objc_class*) + 220
2 libobjc.A.dylib 0x3acd1715 realizeClass(objc_class*) + 220
3 libobjc.A.dylib 0x3acd39ab lookUpImpOrForward + 74
4 libobjc.A.dylib 0x3acd3957 _class_lookupMethodAndLoadCache3 + 34
5 libobjc.A.dylib 0x3acd88b9 _objc_msgSend_uncached + 24
6 itsmysecond-ios 0x001287c7 -[Second getNextSecond:] (Second.m:93)
7 itsmysecond-ios 0x000fd5ff -[EBParallaxViewController adjustViewsToSeconds] (EBParallaxViewController.m:181)
8 itsmysecond-ios 0x000fd21d -[EBParallaxViewController scrollViewDidEndDecelerating:] (EBParallaxViewController.m:154)
9 UIKit 0x32ed6957 -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 806
10 UIKit 0x32e0cd47 -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 466
11 UIKit 0x32e0cb6b -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] + 30
12 UIKit 0x32ed621b -[UIScrollView _smoothScrollWithUpdateTime:] + 3322
13 QuartzCore 0x32a06df3 CA::Display::DisplayLinkItem::dispatch() + 98
14 QuartzCore 0x32a06b9d CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 344
15 IOMobileFramebuffer 0x3577f75d IOMobileFramebufferVsyncNotifyFunc + 104
16 IOKit 0x31209451 IODispatchCalloutFromCFMessage + 248
17 CoreFoundation 0x304ddea9 __CFMachPortPerform + 136
18 CoreFoundation 0x304e8a67 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
19 CoreFoundation 0x304e8a03 __CFRunLoopDoSource1 + 346
20 CoreFoundation 0x304e71d7 __CFRunLoopRun + 1398
21 CoreFoundation 0x30451ebf CFRunLoopRunSpecific + 522
22 CoreFoundation 0x30451ca3 CFRunLoopRunInMode + 106
23 GraphicsServices 0x35357663 GSEventRunModal + 138
24 UIKit 0x32d9e14d UIApplicationMain + 1136
25 itsmysecond-ios 0x00109707 main (main.m:14)
26 libdyld.dylib 0x3b1dbab7 start + 2
I am recording video in my app. My app crashes in iOS 7.0.x only. My application is crashing while writing the captured video in file. Below is my code to setup session & toggle camera
- (BOOL) setupSessionWithPreview:(UIView *)preview usingFrontCamera:(BOOL)frontCamera
{
AVCaptureDevice *videoDevice = nil;
if (frontCamera) {
videoDevice = [self getFrontCamera];
self.videoDeviceType = VideoDeviceTypeFrontCamera;
}
else {
videoDevice = [self getRearCamera];
self.videoDeviceType = VideoDeviceTypeRearCamera;
}
AVCaptureDevice *audioDevice = [self getAudioDevice];
self.videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:videoDevice error:nil];
AVCaptureDeviceInput *audioInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioDevice error:nil];
self.session = [[AVCaptureSession alloc] init];
if([self.session canAddInput:self.videoInput])
[self.session addInput:self.videoInput];
if([self.session canAddInput:audioInput])
[self.session addInput:audioInput];
self.audioOutput = [[AVCaptureAudioDataOutput alloc] init];
dispatch_queue_t audioCaptureQ = dispatch_queue_create("Audio Capture Q", DISPATCH_QUEUE_SERIAL);
[self.audioOutput setSampleBufferDelegate:self queue:audioCaptureQ];
if([self.session canAddOutput:self.audioOutput])
[self.session addOutput:self.audioOutput];
self.audioConnection = [self.audioOutput connectionWithMediaType:AVMediaTypeAudio];
self.videoOutput = [[AVCaptureVideoDataOutput alloc] init];
[self.videoOutput setAlwaysDiscardsLateVideoFrames:YES];
dispatch_queue_t videoCaptureQ = dispatch_queue_create("Video Capture Q", DISPATCH_QUEUE_SERIAL);
[self.videoOutput setSampleBufferDelegate:self queue:videoCaptureQ];
if([self.session canAddOutput:self.videoOutput])
[self.session addOutput:self.videoOutput];
self.videoConnection = [self.videoOutput connectionWithMediaType:AVMediaTypeVideo];
self.videoConnection.videoOrientation = AVCaptureVideoOrientationPortrait;
self.videoOrientation = [self.videoConnection videoOrientation];
movieWriterQ = dispatch_queue_create("Movie Writer Q", DISPATCH_QUEUE_SERIAL);
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];
self.viewLayer = [preview layer];
[self.viewLayer setMasksToBounds:YES];
CGRect bounds = [preview bounds];
[self.previewLayer setFrame:bounds];
[self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[self.viewLayer insertSublayer:self.previewLayer below:[[self.viewLayer sublayers] objectAtIndex:0]];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self.session startRunning];
});
return YES;
}
// Code to toggle camera
-(void)toggleCameraIsFront:(BOOL)isFront
{
AVCaptureDevicePosition desiredPosition;
if (isFront) {
desiredPosition = AVCaptureDevicePositionFront;
self.videoDeviceType = VideoDeviceTypeFrontCamera;
}
else {
desiredPosition = AVCaptureDevicePositionBack;
self.videoDeviceType = VideoDeviceTypeRearCamera;
}
NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in videoDevices)
{
if ([device position] == desiredPosition)
{
AVCaptureDeviceInput *videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
[self.session beginConfiguration];
[self.session removeInput:self.videoInput];
if ([self.session canAddInput:videoDeviceInput])
{
[self.session addInput:videoDeviceInput];
[self setVideoInput:videoDeviceInput];
}
else
{
[self.session addInput:self.videoInput];
}
[self.session removeOutput:self.videoOutput];
AVCaptureVideoDataOutput *videoDeviceOutput = [[AVCaptureVideoDataOutput alloc] init];
if ([self.session canAddOutput:videoDeviceOutput])
{
[self.session addOutput:videoDeviceOutput];
[self setVideoOutput:videoDeviceOutput];
[self.videoOutput setAlwaysDiscardsLateVideoFrames:YES];
// How to manage previously created videoCaptureQ in setupSessionWithPreview method ???
// or do we need create instance variable as dispatch_queue_t videoCaptureQ ???
dispatch_queue_t videoCaptureQ = dispatch_queue_create("Video Capture Q", DISPATCH_QUEUE_SERIAL);
[self.videoOutput setSampleBufferDelegate:self queue:videoCaptureQ];
self.videoConnection = [self.videoOutput connectionWithMediaType:AVMediaTypeVideo];
self.videoConnection.videoOrientation = AVCaptureVideoOrientationPortrait;
self.videoOrientation = [self.videoConnection videoOrientation];
}
else
{
[self.session addOutput:self.videoOutput];
}
[self.session commitConfiguration];
break;
}
}
}
// Code responsible for crashing in iOS 7.0.x ONLY, Works perfectly with iOS 6.x & iOS 7.1
#property(nonatomic, retain) AVAssetWriter *writer;
#property(nonatomic, retain) AVAssetReader *reader;
#property(nonatomic, retain) AVAssetReaderVideoCompositionOutput *videoOut;
#property(nonatomic, retain) AVAssetReaderOutput *audioOut;
#property(nonatomic, retain) AVAssetWriterInput *videoIn;
#property(nonatomic, retain) AVAssetWriterInput *audioIn;
dispatch_group_enter(self.dispatchGroup);
[self.videoIn requestMediaDataWhenReadyOnQueue:self.videoWriterQ usingBlock:^(void) {
if(self.videoFinished)
return;
BOOL completedOrFailed = NO;
while([self.videoIn isReadyForMoreMediaData] && !completedOrFailed)
{
// App crashes here .
CMSampleBufferRef sample = [self.videoOut copyNextSampleBuffer];
if(sample != NULL)
{
BOOL bret = [self.videoIn appendSampleBuffer:sample];
CFRelease(sample);
sample = NULL;
completedOrFailed = !bret;
}
else
{
completedOrFailed = YES;
}
}
if(completedOrFailed)
{
if(!self.videoFinished)
{
[self.videoIn markAsFinished];
}
self.videoFinished = YES;
dispatch_group_leave(self.dispatchGroup);
}
}];
Here is the crash log
Date/Time: 2014-04-07 11:05:34.917 +0100
OS Version: iOS 7.0.6 (11B651)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x7176d7e0
Triggered by Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x3848bb26 objc_msgSend + 6
1 AVFoundation 0x2cf78650 -[AVCaptureVideoDataOutput _applyOverridesToCaptureOptions:] + 168
2 AVFoundation 0x2cf7081c -[AVCaptureSession _resolvedCaptureOptionsByApplyingOverridesToCaptureOptions:preset:] + 344
3 AVFoundation 0x2cf70b2c -[AVCaptureSession _resolvedCaptureOptionsForPreset:audioDevice:videoDevice:] + 108
4 AVFoundation 0x2cf7235c -[AVCaptureSession _buildAndRunGraph] + 312
5 AVFoundation 0x2cf6cc3c -[AVCaptureSession removeInput:] + 1008
6 AVFoundation 0x2cf6ae0c -[AVCaptureSession dealloc] + 172
7 Foundation 0x2e9d1a44 NSKVODeallocate + 60
8 libobjc.A.dylib 0x3849bb06 objc_object::sidetable_release(bool) + 170
9 libobjc.A.dylib 0x3848d002 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 354
10 QuartzCore 0x3043e864 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 64
11 CoreFoundation 0x2e01b1ca __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 18
12 CoreFoundation 0x2e018b6c __CFRunLoopDoObservers + 280
13 CoreFoundation 0x2e018eae __CFRunLoopRun + 726
14 CoreFoundation 0x2df83c22 CFRunLoopRunSpecific + 518
15 CoreFoundation 0x2df83a06 CFRunLoopRunInMode + 102
16 GraphicsServices 0x32caa27e GSEventRunModal + 134
17 UIKit 0x30827044 UIApplicationMain + 1132
18 AppName 0x0013ed06 main (main.m:17)
19 libdyld.dylib 0x38998ab4 start + 0
Thread 1:
0 libsystem_kernel.dylib 0x38a3c83c kevent64 + 24
1 libdispatch.dylib 0x3897d210 _dispatch_mgr_invoke + 228
2 libdispatch.dylib 0x3897cf96 _dispatch_mgr_thread$VARIANT$mp + 34
Thread 2 name: com.apple.NSURLConnectionLoader
Thread 2:
0 libsystem_kernel.dylib 0x38a3ca8c mach_msg_trap + 20
1 libsystem_kernel.dylib 0x38a3c888 mach_msg + 44
2 CoreFoundation 0x2e01a7be __CFRunLoopServiceMachPort + 150
3 CoreFoundation 0x2e018ee4 __CFRunLoopRun + 780
4 CoreFoundation 0x2df83c22 CFRunLoopRunSpecific + 518
5 CoreFoundation 0x2df83a06 CFRunLoopRunInMode + 102
6 Foundation 0x2e9be2f2 +[NSURLConnection(Loader) _resourceLoadLoop:] + 314
7 Foundation 0x2ea33c82 __NSThread__main__ + 1058
8 libsystem_pthread.dylib 0x38ab7c1a _pthread_body + 138
9 libsystem_pthread.dylib 0x38ab7b8a _pthread_start + 98
10 libsystem_pthread.dylib 0x38ab5c8c thread_start + 4
Thread 3 name: com.apple.CFSocket.private
Thread 3:
0 libsystem_kernel.dylib 0x38a4f440 __select + 20
1 CoreFoundation 0x2e01e680 __CFSocketManager + 480
2 libsystem_pthread.dylib 0x38ab7c1a _pthread_body + 138
3 libsystem_pthread.dylib 0x38ab7b8a _pthread_start + 98
4 libsystem_pthread.dylib 0x38ab5c8c thread_start + 4
Thread 4 name: AFNetworking
Thread 4:
0 libsystem_kernel.dylib 0x38a3ca8c mach_msg_trap + 20
1 libsystem_kernel.dylib 0x38a3c888 mach_msg + 44
2 CoreFoundation 0x2e01a7be __CFRunLoopServiceMachPort + 150
3 CoreFoundation 0x2e018ee4 __CFRunLoopRun + 780
4 CoreFoundation 0x2df83c22 CFRunLoopRunSpecific + 518
5 CoreFoundation 0x2df83a06 CFRunLoopRunInMode + 102
6 Foundation 0x2e9713d6 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 250
7 Foundation 0x2e9c230c -[NSRunLoop(NSRunLoop) run] + 76
8 AppName 0x001637b6 +[AFURLConnectionOperation networkRequestThreadEntryPoint:] (AFURLConnectionOperation.m:184)
9 Foundation 0x2ea33c82 __NSThread__main__ + 1058
10 libsystem_pthread.dylib 0x38ab7c1a _pthread_body + 138
11 libsystem_pthread.dylib 0x38ab7b8a _pthread_start + 98
12 libsystem_pthread.dylib 0x38ab5c8c thread_start + 4
Thread 5 name: com.apple.coremedia.player.async
Thread 5:
0 libsystem_kernel.dylib 0x38a3cadc semaphore_wait_trap + 8
1 libdispatch.dylib 0x3897b428 _dispatch_semaphore_wait_slow + 172
2 MediaToolbox 0x2f46f83c fpa_AsyncMovieControlThread + 1752
3 CoreMedia 0x2e5ae234 figThreadMain + 192
4 libsystem_pthread.dylib 0x38ab7c1a _pthread_body + 138
5 libsystem_pthread.dylib 0x38ab7b8a _pthread_start + 98
6 libsystem_pthread.dylib 0x38ab5c8c thread_start + 4
Thread 6:
0 libsystem_kernel.dylib 0x38a3ca8c mach_msg_trap + 20
1 libsystem_kernel.dylib 0x38a3c888 mach_msg + 44
2 CoreFoundation 0x2e01a7be __CFRunLoopServiceMachPort + 150
3 CoreFoundation 0x2e018ee4 __CFRunLoopRun + 780
4 CoreFoundation 0x2df83c22 CFRunLoopRunSpecific + 518
5 CoreFoundation 0x2df83a06 CFRunLoopRunInMode + 102
6 libAVFAudio.dylib 0x2d006584 GenericRunLoopThread::Entry(void*) + 124
7 libAVFAudio.dylib 0x2cffa99c CAPThread::Entry(CAPThread*) + 176
8 libsystem_pthread.dylib 0x38ab7c1a _pthread_body + 138
9 libsystem_pthread.dylib 0x38ab7b8a _pthread_start + 98
10 libsystem_pthread.dylib 0x38ab5c8c thread_start + 4
Thread 7 name: com.apple.coremedia.player.async
Thread 7:
0 libsystem_kernel.dylib 0x38a3cadc semaphore_wait_trap + 8
1 libdispatch.dylib 0x3897b428 _dispatch_semaphore_wait_slow + 172
2 MediaToolbox 0x2f46f83c fpa_AsyncMovieControlThread + 1752
3 CoreMedia 0x2e5ae234 figThreadMain + 192
4 libsystem_pthread.dylib 0x38ab7c1a _pthread_body + 138
5 libsystem_pthread.dylib 0x38ab7b8a _pthread_start + 98
6 libsystem_pthread.dylib 0x38ab5c8c thread_start + 4
Thread 8 name: com.apple.coremedia.player.remote
Thread 8:
0 libsystem_kernel.dylib 0x38a3ca8c mach_msg_trap + 20
1 libsystem_kernel.dylib 0x38a3c888 mach_msg + 44
2 MediaToolbox 0x2f475c58 FigExpressNotificationThread + 84
3 CoreMedia 0x2e5ae234 figThreadMain + 192
4 libsystem_pthread.dylib 0x38ab7c1a _pthread_body + 138
5 libsystem_pthread.dylib 0x38ab7b8a _pthread_start + 98
6 libsystem_pthread.dylib 0x38ab5c8c thread_start + 4
Thread 9:
0 libsystem_kernel.dylib 0x38a3ca8c mach_msg_trap + 20
1 libsystem_kernel.dylib 0x38a3c888 mach_msg + 44
2 CoreFoundation 0x2e01a7be __CFRunLoopServiceMachPort + 150
3 CoreFoundation 0x2e018ee4 __CFRunLoopRun + 780
4 CoreFoundation 0x2df83c22 CFRunLoopRunSpecific + 518
5 CoreFoundation 0x2dfc7736 CFRunLoopRun + 94
6 CoreMotion 0x2e63a230 ___lldb_unnamed_function1404$$CoreMotion + 724
7 libsystem_pthread.dylib 0x38ab7c1a _pthread_body + 138
8 libsystem_pthread.dylib 0x38ab7b8a _pthread_start + 98
9 libsystem_pthread.dylib 0x38ab5c8c thread_start + 4
Thread 10 name: com.apple.coremedia.player.async
Thread 10:
0 libsystem_kernel.dylib 0x38a3cadc semaphore_wait_trap + 8
1 libdispatch.dylib 0x3897b428 _dispatch_semaphore_wait_slow + 172
2 MediaToolbox 0x2f46f83c fpa_AsyncMovieControlThread + 1752
3 CoreMedia 0x2e5ae234 figThreadMain + 192
4 libsystem_pthread.dylib 0x38ab7c1a _pthread_body + 138
5 libsystem_pthread.dylib 0x38ab7b8a _pthread_start + 98
6 libsystem_pthread.dylib 0x38ab5c8c thread_start + 4
Thread 11:
0 libsystem_kernel.dylib 0x38a4fc7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x38ab5dc6 _pthread_wqthread + 306
2 libsystem_pthread.dylib 0x38ab5c80 start_wqthread + 4
Thread 12:
0 libsystem_kernel.dylib 0x38a4fc7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x38ab5dc6 _pthread_wqthread + 306
2 libsystem_pthread.dylib 0x38ab5c80 start_wqthread + 4
Thread 13:
0 libsystem_kernel.dylib 0x38a3ca8c mach_msg_trap + 20
1 libsystem_kernel.dylib 0x38a3c888 mach_msg + 44
2 MediaToolbox 0x2f588594 FigRemakerFamilyClient_ReaderExtractAndRetainNextSampleBuffer + 92
3 MediaToolbox 0x2f5835a0 remoteReader_ExtractAndRetainNextSampleBuffer + 108
4 AVFoundation 0x2cf2a8ba -[AVAssetReaderOutput copyNextSampleBuffer] + 222
5 AppName 0x0016a320 __36-[MediaWriter performWrite:onError:]_block_invoke141 (MediaWriter.m:188)
6 AVFoundation 0x2cf3d810 -[AVAssetWriterInputMediaDataRequester requestMediaDataIfNecessary] + 84
7 libdispatch.dylib 0x38973d18 _dispatch_call_block_and_release + 8
8 libdispatch.dylib 0x3897a26e _dispatch_queue_drain$VARIANT$mp + 370
9 libdispatch.dylib 0x3897a066 _dispatch_queue_invoke$VARIANT$mp + 38
10 libdispatch.dylib 0x3897acde _dispatch_root_queue_drain + 74
11 libdispatch.dylib 0x3897af54 _dispatch_worker_thread2 + 52
12 libsystem_pthread.dylib 0x38ab5dbc _pthread_wqthread + 296
13 libsystem_pthread.dylib 0x38ab5c80 start_wqthread + 4
Thread 14 name: com.apple.coremedia.player.async
Thread 14:
0 libsystem_kernel.dylib 0x38a3cadc semaphore_wait_trap + 8
1 libdispatch.dylib 0x3897b428 _dispatch_semaphore_wait_slow + 172
2 MediaToolbox 0x2f46f83c fpa_AsyncMovieControlThread + 1752
3 CoreMedia 0x2e5ae234 figThreadMain + 192
4 libsystem_pthread.dylib 0x38ab7c1a _pthread_body + 138
5 libsystem_pthread.dylib 0x38ab7b8a _pthread_start + 98
6 libsystem_pthread.dylib 0x38ab5c8c thread_start + 4
Thread 15:
0 libsystem_kernel.dylib 0x38a4fc7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x38ab5dc6 _pthread_wqthread + 306
2 libsystem_pthread.dylib 0x38ab5c80 start_wqthread + 4
Thread 16:
0 libsystem_kernel.dylib 0x38a4fc7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x38ab5dc6 _pthread_wqthread + 306
2 libsystem_pthread.dylib 0x38ab5c80 start_wqthread + 4
Thread 17:
0 libsystem_kernel.dylib 0x38a3ca8c mach_msg_trap + 20
1 libsystem_kernel.dylib 0x38a3c888 mach_msg + 44
2 MediaToolbox 0x2f5896b4 FigRemakerFamilyClient_WriterAddSampleBuffer + 112
3 MediaToolbox 0x2f581bec remoteWriter_AddSampleBuffer + 236
4 AVFoundation 0x2cf3c144 -[AVFigAssetWriterTrack addSampleBuffer:error:] + 84
5 AVFoundation 0x2cf3cfcc -[AVFigAssetWriterAudioTrack addSampleBuffer:error:] + 300
6 AVFoundation 0x2cf39afa -[AVAssetWriterInputWritingHelper appendSampleBuffer:] + 74
7 AVFoundation 0x2cf37d62 -[AVAssetWriterInput appendSampleBuffer:] + 46
8 AppName 0x0016a190 __36-[MediaWriter performWrite:onError:]_block_invoke (MediaWriter.m:162)
9 AVFoundation 0x2cf3d810 -[AVAssetWriterInputMediaDataRequester requestMediaDataIfNecessary] + 84
10 libdispatch.dylib 0x38973d18 _dispatch_call_block_and_release + 8
11 libdispatch.dylib 0x3897a26e _dispatch_queue_drain$VARIANT$mp + 370
12 libdispatch.dylib 0x3897a066 _dispatch_queue_invoke$VARIANT$mp + 38
13 libdispatch.dylib 0x3897acde _dispatch_root_queue_drain + 74
14 libdispatch.dylib 0x3897af54 _dispatch_worker_thread2 + 52
15 libsystem_pthread.dylib 0x38ab5dbc _pthread_wqthread + 296
16 libsystem_pthread.dylib 0x38ab5c80 start_wqthread + 4
Thread 18:
0 libsystem_kernel.dylib 0x38a3e664 fsync + 8
1 libsqlite3.dylib 0x3876d73c ___lldb_unnamed_function199$$libsqlite3.dylib + 44
2 libsqlite3.dylib 0x387a59e8 ___lldb_unnamed_function529$$libsqlite3.dylib + 1168
3 libsqlite3.dylib 0x3876d138 ___lldb_unnamed_function197$$libsqlite3.dylib + 336
4 libsqlite3.dylib 0x38763004 ___lldb_unnamed_function156$$libsqlite3.dylib + 552
5 libsqlite3.dylib 0x38744638 ___lldb_unnamed_function56$$libsqlite3.dylib + 1496
6 libsqlite3.dylib 0x3875fc32 ___lldb_unnamed_function123$$libsqlite3.dylib + 38026
7 libsqlite3.dylib 0x38755e2c sqlite3_step + 404
8 libsqlite3.dylib 0x38734952 sqlite3_exec + 358
9 CFNetwork 0x2dc14d30 __CFURLCache::ExecSQLStatement_NoLock(sqlite3*, char const*, int (*)(void*, int, char**, char**), void*, long) + 32
10 CFNetwork 0x2dc84bb8 __CFURLCache::_PreProcessCacheTasks() + 108
11 CFNetwork 0x2dc849da __CFURLCache::_CFURLCacheTimerCallback0() + 630
12 CFNetwork 0x2dc84754 __CFURLCache::_CFURLCacheTimerCallback(void*) + 28
13 libdispatch.dylib 0x3897c7fe _dispatch_source_invoke$VARIANT$mp + 258
14 libdispatch.dylib 0x3897a232 _dispatch_queue_drain$VARIANT$mp + 310
15 libdispatch.dylib 0x3897a066 _dispatch_queue_invoke$VARIANT$mp + 38
16 libdispatch.dylib 0x3897acde _dispatch_root_queue_drain + 74
17 libdispatch.dylib 0x3897af54 _dispatch_worker_thread2 + 52
18 libsystem_pthread.dylib 0x38ab5dbc _pthread_wqthread + 296
19 libsystem_pthread.dylib 0x38ab5c80 start_wqthread + 4
Thread 0 crashed with ARM Thread State (32-bit):
r0: 0x176f9f60 r1: 0x30daa1e8 r2: 0x2cfeb38f r3: 0x00000000
r4: 0x30dba133 r5: 0x18e7bde0 r6: 0x30dad051 r7: 0x27d087f8
r8: 0x38b3fc28 r9: 0x7176d7d4 r10: 0x1903c100 r11: 0x18fdbd70
ip: 0x38b1e868 sp: 0x27d087c4 lr: 0x2cf78655 pc: 0x3848bb26
cpsr: 0x60000030
Can anybody tell me what's going wrong in iOS 7.0.x ONLY ? On other iOS versions its working correctly. Any kind of help is appreciated.
Thanks.
Did you dealloc correctly?
Try adding these lines to your dealloc method,
[self.session removeInput:self.videoIn];
[self.session removeOutput:self.videoOut];
Building against MT 6.0.4.
Targeting iOS 4.
Testing on an iPhone 4S.
I'm stumped as to what I am doing wrong. I display the ABPeoplePickerNavigationController modally after subscribing to the SelectPerson event. Within the event, I take a copy of the data I need (only holding references to strings, not to any of the AdressBook or Person instances), and then close the modal dialog:
private string selectedPersonFirstName;
private string selectedPersonEmail;
private string selectedPersonPhone;
private void SelectContact()
{
var peoplePicker = new ABPeoplePickerNavigationController();
peoplePicker.Cancelled += (sender, e) =>
{
selectedPersonFirstName = null;
selectedPersonEmail = null;
selectedPersonPhone = null;
peoplePicker.DismissViewController(true, null);
};
peoplePicker.SelectPerson += (sender, e) =>
{
var selectedName = String.Format("{0} {1}", e.Person.FirstName, e.Person.LastName);
selectedPersonFirstName = e.Person.FirstName;
if ( e.Person.GetEmails().Count > 0)
selectedPersonEmail = e.Person.GetEmails().FirstOrDefault().Value;
if ( e.Person.GetPhones().Count > 0)
selectedPersonPhone = e.Person.GetPhones().FirstOrDefault().Value;
peoplePicker.DismissViewController(true, null);
};
PresentViewController(peoplePicker, true, null);
}
At some point later when the GC kicks in, it crashes:
Stacktrace:
at MonoTouch.Foundation.NSObject.FinishDispose () [0x0000b] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.cs:158
at MonoTouch.Foundation.NSObject/MonoTouch_Disposer.Drain (MonoTouch.Foundation.NSObject) [0x00062] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.cs:376
at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at MyApp.iOS.Application.Main (string[]) [0x00000] in /Users/tyson/Code/MyApp/iOS/Main.cs:19
at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
Native stacktrace:
0 MyAppName--------------- 0x00f574f4 mono_handle_native_sigsegv + 280
1 MyAppName--------------- 0x00f3a2b8 mono_sigsegv_signal_handler + 268
2 libsystem_c.dylib 0x31ae97ed _sigtramp + 48
3 CoreFoundation 0x3745b2e7 CFRelease + 94
4 AddressBookUI 0x373922d1 -[ABGroupWrapper dealloc] + 100
5 libobjc.A.dylib 0x35a14175 _objc_rootRelease + 36
6 AddressBookUI 0x373a3f57 -[ABModel dealloc] + 146
7 libobjc.A.dylib 0x35a14175 _objc_rootRelease + 36
8 AddressBookUI 0x373aec43 -[ABAbstractViewController dealloc] + 38
9 AddressBookUI 0x373aeb3d -[ABMembersViewController dealloc] + 216
10 libobjc.A.dylib 0x35a14175 _objc_rootRelease + 36
11 CoreFoundation 0x3745b2e7 CFRelease + 94
12 CoreFoundation 0x3747106b -[__NSArrayM dealloc] + 122
13 libobjc.A.dylib 0x35a14175 _objc_rootRelease + 36
14 UIKit 0x33c891b9 -[UIViewController dealloc] + 496
15 UIKit 0x33c88f2f -[UINavigationController dealloc] + 198
16 AddressBookUI 0x373adcbd -[ABPeoplePickerNavigationController dealloc] + 376
17 libobjc.A.dylib 0x35a14175 _objc_rootRelease + 36
18 MyAppName--------------- 0x001e1ccc wrapper_managed_to_native_MonoTouch_ObjCRuntime_Messaging_void_objc_msgSend_intptr_intptr + 68
19 MyAppName--------------- 0x001ad49c MonoTouch_Foundation_NSObject_MonoTouch_Disposer_Drain_MonoTouch_Foundation_NSObject + 364
20 MyAppName--------------- 0x006997b8 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
21 MyAppName--------------- 0x00f3c6a4 mono_jit_runtime_invoke + 1644
22 MyAppName--------------- 0x00ff5dc0 mono_runtime_invoke + 128
23 MyAppName--------------- 0x00f2c6ec native_to_managed_trampoline_MonoTouch_Foundation_NSObject_MonoTouch_Disposer_Drain + 280
24 CoreFoundation 0x374a0eef +[NSObject performSelector:withObject:] + 42
25 Foundation 0x37d51747 __NSThreadPerformPerform + 350
26 CoreFoundation 0x374e6ad3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
27 CoreFoundation 0x374e629f __CFRunLoopDoSources0 + 214
28 CoreFoundation 0x374e5045 __CFRunLoopRun + 652
29 CoreFoundation 0x374684a5 CFRunLoopRunSpecific + 300
30 CoreFoundation 0x3746836d CFRunLoopRunInMode + 104
31 GraphicsServices 0x32375439 GSEventRunModal + 136
32 UIKit 0x33bece7d UIApplicationMain + 1080
33 MyAppName--------------- 0x001e6ca4 wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 240
34 MyAppName--------------- 0x00ee0210 MyApp_iOS_Application_Main_string__ + 152
35 MyAppName--------------- 0x006997b8 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
36 MyAppName--------------- 0x00f3c6a4 mono_jit_runtime_invoke + 1644
37 MyAppName--------------- 0x00ff5dc0 mono_runtime_invoke + 128
38 MyAppName--------------- 0x00ffa224 mono_runtime_exec_main + 436
39 MyAppName--------------- 0x00fff770 mono_runtime_run_main + 756
40 MyAppName--------------- 0x00f434a4 mono_jit_exec + 140
41 MyAppName--------------- 0x0105c04c main + 2028
42 MyAppName--------------- 0x0001bd18 start + 40
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
Has anyone seen anything like this before? I'm up for workarounds at this point as I need it more reliable for a demo ASAP (not for app store submission yet).
It looks like a bug. Something gets released one time too many and crash.
You can, for your demonstration purpose, work around it by defining CFRetain like this:
[System.Runtime.InteropServices.DllImport ("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
static extern IntPtr CFRetain (IntPtr obj);
and use it on the _AddressBook, like that
peoplePicker.SelectPerson += (sender, e) => {
CFRetain (peoplePicker._AddressBook);
var selectedName = String.Format("{0} {1}", e.Person.FirstName, e.Person.LastName);
...
That will balance the count and avoid the crash.
Update: bug filled, you can c.c. yourself the the bug report to know when a fix will be released.
After I have updated monotouch to Version 5.2.13 my App crashes when I touched inside a UIButton.
About my Code: (it's a question of a LoginView):
I have a UIViewController which includes a ScrollView.
For each User the ScrollView provides a UIView (the UserImageView).
This UserImageView contains a UserImage, Username and so on. Over the UserImage lays a UIButton which should catches the Touch-Events to selected a User.
This Button causes the Exception below more precisely the HitTest method from the UIView.
I get the following Stacktrace:
Stacktrace:
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at MF.Stationaer.iPad.Application.Main (string[]) <IL 0x00028, 0x00073>
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Native stacktrace:
0 MFiPad_MD 0x0009061c mono_handle_native_sigsegv + 284
1 MFiPad_MD 0x000059a8 mono_sigsegv_signal_handler + 248
2 libsystem_c.dylib 0x92cd259b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 UIKit 0x0228c741 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 96
5 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
6 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
7 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
8 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
9 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
10 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
11 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
12 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
13 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
14 UIKit 0x022a1157 -[UIScrollView hitTest:withEvent:] + 79
15 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
16 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
17 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
18 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
19 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
20 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
21 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
22 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
23 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
24 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
25 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
26 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
27 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
28 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
29 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
30 UIKit 0x02286dbd +[UIWindow _hitTestToPoint:pathIndex:forEvent:] + 378
31 UIKit 0x02258ca0 _UIApplicationHandleEvent + 1648
32 GraphicsServices 0x047c5ef5 PurpleEventCallback + 1274
33 CoreFoundation 0x011a9195 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
34 CoreFoundation 0x0110dff2 __CFRunLoopDoSource1 + 146
35 CoreFoundation 0x0110c8da __CFRunLoopRun + 2218
36 CoreFoundation 0x0110bd84 CFRunLoopRunSpecific + 212
37 CoreFoundation 0x0110bc9b CFRunLoopRunInMode + 123
38 GraphicsServices 0x047c47d8 GSEventRunModal + 190
39 GraphicsServices 0x047c488a GSEventRun + 103
40 UIKit 0x02258626 UIApplicationMain + 1163
41 ??? 0x0b96e514 0x0 + 194438420
42 ??? 0x0b96d6c0 0x0 + 194434752
43 ??? 0x0b96d33c 0x0 + 194433852
44 ??? 0x0b96d42f 0x0 + 194434095
45 MFiPad_MD 0x00009d12 mono_jit_runtime_invoke + 722
46 MFiPad_MD 0x00169e4e mono_runtime_invoke + 126
47 MFiPad_MD 0x0016df34 mono_runtime_exec_main + 420
48 MFiPad_MD 0x001732e5 mono_runtime_run_main + 725
49 MFiPad_MD 0x00066f15 mono_jit_exec + 149
50 MFiPad_MD 0x002115d5 main + 2837
51 MFiPad_MD 0x00002d65 start + 53
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
Here is the important Part of my Code:
public class LoginViewController : UIViewController
{
...
public override void ViewDidLoad()
{
...
BuildUserUI();
...
}
private void BuildUserUI()
{
currentIconLocation = new PointF(50, 10);
for (var i = 0; i < UserList.List.Count; i++)
CreateUserInGrid(UserList.GetUserByIndex(i));
}
private void CreateUserInGrid(LoginUser user)
{
var imgFrame = new RectangleF(currentIconLocation.X, currentIconLocation.Y, 140, 170);
var loginImg = new UILoginImage(imgFrame);
loginImg.Image = user.Image ?? defaultUserImage.CGImage;
loginImg.Name = user.Nachname;
if (!string.IsNullOrEmpty(user.Vorname))
loginImg.Name += ", " + user.Vorname;
loginImg.Tag = user.UserIndex;
loginImg.AddTarget(this, new Selector("ShowNumberPad:"), UIControlEvent.TouchUpInside);
loginImg.LoginUser = user;
scrollView.AddSubview(loginImg);
loginImages.Add(loginImg);
limitedScrollView.UserInteractionEnabled = false;
var newSize = new SizeF(scrollView.Frame.Size.Width, currentIconLocation.Y + imgFrame.Size.Height + 20);
scrollView.ContentSize = newSize;
limitedScrollView.ContentSize = new SizeF(limitedScrollView.Frame.Size.Width, limitedScrollView.Frame.Size.Height);
currentIconLocation.X += imgFrame.Size.Width;
if (currentIconLocation.X + imgFrame.Size.Width > scrollView.Frame.Size.Width)
{
currentIconLocation.Y += imgFrame.Size.Height;
currentIconLocation.X = 50;
}
}
[Export("ShowNumberPad:")]
private void ShowNumberPad(NSObject sender)
{
...
}
}
public class UILoginImage : UIView
{
[Export("initWithFrame:")]
public UILoginImage(RectangleF frame)
: base(frame)
{
var shadowFrame = new RectangleF(0, 0, 117, 148);
wrapperControl = new UIControl(shadowFrame);
AddSubview(wrapperControl);
shadowImage = new UIImageView(shadowFrame);
shadowImage.Image = ImageCache.GetResourceImage("Images/Login/LoginSchatten.png");
wrapperControl.AddSubview(shadowImage);
var mainBackFrame = new RectangleF(8, 9, 98, 128);
whiteBackgroundImage = new UIImageView(mainBackFrame);
whiteBackgroundImage.Image = ImageCache.GetResourceImage("Images/Login/Singlewhite.png");
wrapperControl.AddSubview(whiteBackgroundImage);
var imageFrame = new RectangleF(13, 15, 87, 116);
clickHelper = UIButton.FromType(UIButtonType.Custom);
clickHelper.Frame = imageFrame;
wrapperControl.AddSubview(clickHelper);
userImage = new UIImageView(imageFrame);
AddSubview(userImage);
var mitarbeiterlabelFrame = new RectangleF(-12, 137, 140, 25);
mitarbeiterNameLabel = new FontSizeLabel(mitarbeiterlabelFrame);
mitarbeiterNameLabel.TextAlignment = UITextAlignment.Center;
mitarbeiterNameLabel.Font = UIFont.SystemFontOfSize(12);
mitarbeiterNameLabel.Opaque = false;
mitarbeiterNameLabel.BackgroundColor = UIColor.Clear;
AddSubview(mitarbeiterNameLabel);
var benutzerlabelFrame = new RectangleF(mitarbeiterlabelFrame.X, mitarbeiterlabelFrame.Y + 13, 140, 25);
benutzerNameLabel = new FontSizeLabel(benutzerlabelFrame);
benutzerNameLabel.TextAlignment = UITextAlignment.Center;
benutzerNameLabel.Font = UIFont.SystemFontOfSize(10);
benutzerNameLabel.Opaque = false;
benutzerNameLabel.BackgroundColor = UIColor.Clear;
benutzerNameLabel.TextColor = UIColor.DarkGray;
AddSubview(benutzerNameLabel);
}
public void AddTarget(NSObject target, Selector action, UIControlEvent controlEvents)
{
clickHelper.AddTarget(target, action, controlEvents);
}
public void RemoveTarget(NSObject target, Selector action, UIControlEvent controlEvents)
{
clickHelper.RemoveTarget(target, action, controlEvents);
}
}
I'm not sure your use of AddTarget is a good way to hook up a UIButton's click.
You should be using clickHelper.TouchUpInside to wire up click events. This is a standard C# event.
Another option would be to wire up an action to this event inside your XIB file in XCode.