Re: Crash with ARC enabled on Xcode 6.1
Re: Crash with ARC enabled on Xcode 6.1
- Subject: Re: Crash with ARC enabled on Xcode 6.1
- From: Kevin Meaney <email@hidden>
- Date: Thu, 23 Oct 2014 10:18:52 +0100
On 23 Oct 2014, at 00:34, Beinan Li <email@hidden> wrote:
> Oh! I did actually.
>
> The method I posted belongs to an ObjC object which is wrapped by a C++ object.
> That C++ object is a singleton (static).
>
> How is this going to affect ARC and why it didn't down-right crash a week ago before I upgraded Xcode?
I wouldn't worry about why it worked before. I don't think that helps, and if you have any other cases they should be removed as well.
Array and dictionary literals are not evaluated at compile time but are replaced with the objective-c calls to create the arrays and dictionaries. This is very different to string literals.
From what I understand any code that is executed before main is called is done so before the objective-c runtime is fully setup which means you have no guarantees about what will work. In objective-c++ where you can create static C++ objects that results in objective-c being called it is an easy way to make difficult to track crashes.
I'd like confirmation from an apple engineer that my understanding is correct. My quick perusal of the docs didn't find the info I was after.
Kevin
> Thanks,
> Beinan
>
>
> On Wed, Oct 22, 2014 at 7:00 PM, Kevin Meaney <email@hidden> wrote:
> Your not creating a static C++ object anywhere are you? One that creates the dictionary before main gets called by any chance?
>
> Kevin
>
> Sent from my iPhone
>
> > On 22 Oct 2014, at 22:45, Beinan Li <email@hidden> wrote:
> >
> > Note, the initial crashing function is merely translating a C++ enum to the
> > AVFoundation builtin constants.
> >
> > Thanks,
> > Beinan
> >
> >
> >> On Wed, Oct 22, 2014 at 5:45 PM, Beinan Li <email@hidden> wrote:
> >>
> >> It is quite unpredictable.
> >> At first it crashes at a dictionary creation line in a .mm implementation
> >> like this:
> >>
> >> - (NSString*) getAVAudioSessionMode:(myAudioSessionMode)modeKey {
> >> NSDictionary* modeDict = @{ // Here it crashes
> >> @(myAudioSessionModeDefault): AVAudioSessionModeDefault,
> >> @(myAudioSessionModeVoiceChat): AVAudioSessionModeVoiceChat,
> >> @(myAudioSessionModeGameChat): AVAudioSessionModeGameChat,
> >> @(myAudioSessionModeVideoRecording): AVAudioSessionModeVideoRecording,
> >> @(myAudioSessionModeMeasurement): AVAudioSessionModeMeasurement,
> >> @(myAudioSessionModeMoviePlayback): AVAudioSessionModeMoviePlayback,
> >> @(myAudioSessionModeVideoChat): AVAudioSessionModeVideoChat
> >> };
> >> NSString* mode = [modeDict objectForKey:@
> >> (mySettings.audioSession.eMode)];
> >> return mode;
> >> }
> >>
> >> The backtrace gives me:
> >>
> >> * thread #1: tid = 0x2403, 0x0013148c MyDemo`-[MyImp
> >> getAVAudioSessionMode:](self=0x1e839a80, _cmd=0x002d3077,
> >> modeKey=myAudioSessionModeDefault) + 676 at MyImp.mm:78, queue =
> >> 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
> >> * frame #0:
> >> 0x0013148c MyDemo -[MyImp getAVAudioSessionMode:](self=0x1e839a80,
> >> _cmd=0x002d3077, modeKey=myAudioSessionModeDefault) + 676 at MyImp.mm:78
> >>
> >> Then if I remove this dictionary all together and do it like this:
> >>
> >> - (NSString*) getAVAudioSessionMode:(myAudioSessionMode)modeKey {
> >> return AVAudioSessionModeDefault;
> >> }
> >>
> >> Then I get a crash right in the main.mm:
> >>
> >> int retVal = UIApplicationMain(argc, argv, nil, @"MyDemoAppDelegate");
> >>
> >> backtrace:
> >>
> >> * thread #1: tid = 0x2403, 0x3c4df350
> >> libsystem_kernel.dylib`__pthread_kill + 8, queue = 'com.apple.main-thread',
> >> stop reason = signal SIGABRT
> >> frame #0: 0x3c4df350 libsystem_kernel.dylib`__pthread_kill + 8
> >> frame #1: 0x3c456122 libsystem_c.dylib`pthread_kill + 58
> >> frame #2: 0x3c492972 libsystem_c.dylib`abort + 94
> >> frame #3: 0x3ba30d4e libc++abi.dylib`abort_message + 74
> >> frame #4: 0x3ba2dff8 libc++abi.dylib`default_terminate() + 24
> >> frame #5: 0x3bfe1a
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden