Application crashes unless run from Xcode - objective-c

I have this code:
NSColor *color = [NSColor colorWithDeviceHue:hue
saturation:saturation
brightness:brightness
alpha:1.0];
NSString *scriptString = [NSString stringWithFormat:
#"try\n"
#"tell application \"Adobe Photoshop CS5\" \n"
#"set foreground color to {class:RGB color, red:%f, green:%f, blue:%f} \n"
#"end tell\n"
#"on error\n"
#"try\n"
#"tell application \"Adobe Photoshop CS4\" \n"
#"set foreground color to {class:RGB color, red:%f, green:%f, blue:%f} \n"
#"end tell\n"
#"end try\n"
#"end try",
[color redComponent] * 255,
[color greenComponent] * 255,
[color blueComponent] * 255];
NSLog(#"script string: %#", scriptString);
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:scriptString];
NSDictionary *error;
[script executeAndReturnError:&error];
NSLog(#"result: %#", error);
When I run it from xcode's run feature, it works just fine. When I build it as an application and run it standalone, it quite often crashes in this part.
Any idea why this might be?
EDIT: Most of the crash log (can't fit it all in here)
Process: The Color Picker Sync [1283]
Path: /Users/USER/*/The Color Picker Sync.app/Contents/MacOS/The Color Picker Sync
Identifier: com.Loupe.The-Color-Picker-Sync
Version: 1.1 (1.1)
Code Type: X86-64 (Native)
Parent Process: launchd [160]
Date/Time: 2012-01-21 14:04:54.025 +0000
OS Version: Mac OS X 10.7.2 (11C74)
Report Version: 9
Sleep/Wake UUID: 6BFBE167-51ED-433B-BB70-17D6C4054817
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: 0x000000000000000d, 0x0000000000000000
VM Regions Near 0:
-->
__TEXT 0000000101782000-000000010178c000 [ 40K] r-x/rwx SM=COW /Users/USER/*/The Color Picker Sync.app/Contents/MacOS/The Color Picker Sync
Application Specific Information:
objc_msgSend() selector name: respondsToSelector:
objc[1283]: garbage collection is OFF
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff90d8114d objc_msgSend_vtable5 + 13
1 com.apple.Foundation 0x00007fff8c239456 _NSDescriptionWithLocaleFunc + 50
2 com.apple.CoreFoundation 0x00007fff911284d5 __CFStringAppendFormatCore + 11365
3 com.apple.CoreFoundation 0x00007fff9117acdb _CFStringCreateWithFormatAndArgumentsAux + 107
4 com.apple.CoreFoundation 0x00007fff911f3182 _CFLogvEx + 114
5 com.apple.Foundation 0x00007fff8c2b3b53 NSLogv + 89
6 com.apple.Foundation 0x00007fff8c2b3af1 NSLog + 130
7 com.Loupe.The-Color-Picker-Sync 0x0000000101784103 -[StatusMenuItemSampleAppDelegate didReceiveMessage:] + 1023 (StatusMenuItemSampleAppDelegate.m:294)
8 com.Loupe.The-Color-Picker-Sync 0x00000001017848fb -[LocalRoom receivedNetworkPacket:viaConnection:] + 104 (LocalRoom.m:161)
9 com.Loupe.The-Color-Picker-Sync 0x0000000101785aa2 -[NetworkConnection readFromStreamIntoIncomingBuffer] + 416 (NetworkConnection.m:359)
10 com.apple.CoreFoundation 0x00007fff91183b7b _signalEventSync + 107
11 com.apple.CoreFoundation 0x00007fff91183b02 _cfstream_solo_signalEventSync + 98
12 com.apple.CoreFoundation 0x00007fff91183928 _CFStreamSignalEvent + 632
13 com.apple.CFNetwork 0x00007fff87459613 SocketStream::dispatchSignalFromSocketCallbackUnlocked(SocketStreamSignalHolder*) + 45
14 com.apple.CFNetwork 0x00007fff87458c72 SocketStream::socketCallback(__CFSocket*, unsigned long, __CFData const*, void const*) + 232
15 com.apple.CFNetwork 0x00007fff87458b72 SocketStream::_SocketCallBack_stream(__CFSocket*, unsigned long, __CFData const*, void const*, void*) + 100
16 com.apple.CoreFoundation 0x00007fff9117b714 __CFSocketPerformV0 + 980
17 com.apple.CoreFoundation 0x00007fff91133b51 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
18 com.apple.CoreFoundation 0x00007fff911333bd __CFRunLoopDoSources0 + 253
19 com.apple.CoreFoundation 0x00007fff9115a1a9 __CFRunLoopRun + 905
20 com.apple.CoreFoundation 0x00007fff91159ae6 CFRunLoopRunSpecific + 230
21 com.apple.HIToolbox 0x00007fff8e14d3d3 RunCurrentEventLoopInMode + 277
22 com.apple.HIToolbox 0x00007fff8e15463d ReceiveNextEventCommon + 355
23 com.apple.HIToolbox 0x00007fff8e1544ca BlockUntilNextEventMatchingListInMode + 62
24 com.apple.AppKit 0x00007fff8c5533f1 _DPSNextEvent + 659
25 com.apple.AppKit 0x00007fff8c552cf5 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
26 com.apple.AppKit 0x00007fff8c54f62d -[NSApplication run] + 470
27 com.apple.AppKit 0x00007fff8c7ce80c NSApplicationMain + 867
28 com.Loupe.The-Color-Picker-Sync 0x000000010178302c 0x101782000 + 4140
Thread 1:: Dispatch queue: com.apple.libdispatch-manager
0 libsystem_kernel.dylib 0x00007fff8b3cc7e6 kevent + 10
1 libdispatch.dylib 0x00007fff8bf615be _dispatch_mgr_invoke + 923
2 libdispatch.dylib 0x00007fff8bf6014e _dispatch_mgr_thread + 54
Thread 2:: com.apple.CFSocket.private
0 libsystem_kernel.dylib 0x00007fff8b3cbdf2 __select + 10
1 com.apple.CoreFoundation 0x00007fff911a2f9b __CFSocketManager + 1355
2 libsystem_c.dylib 0x00007fff90aad8bf _pthread_start + 335
3 libsystem_c.dylib 0x00007fff90ab0b75 thread_start + 13
Thread 3:
0 libsystem_kernel.dylib 0x00007fff8b3cc192 __workq_kernreturn + 10
1 libsystem_c.dylib 0x00007fff90aaf594 _pthread_wqthread + 758
2 libsystem_c.dylib 0x00007fff90ab0b85 start_wqthread + 13
Thread 4:
0 libsystem_kernel.dylib 0x00007fff8b3cc192 __workq_kernreturn + 10
1 libsystem_c.dylib 0x00007fff90aaf594 _pthread_wqthread + 758
2 libsystem_c.dylib 0x00007fff90ab0b85 start_wqthread + 13
Thread 0 crashed with X86 Thread State (64-bit):
rax: 0x0000000000000000 rbx: 0x0000000000000000 rcx: 0x00007fff6137ec80 rdx: 0x00007fff8c481ccc
rdi: 0x20200a3b31203d20 rsi: 0x00007fff76a0f730 rbp: 0x00007fff6137e970 rsp: 0x00007fff6137e958
r8: 0x000000000000000a r9: 0x000000000000057e r10: 0x0000000000000000 r11: 0x00007fca58557e21
r12: 0x00007fff91128644 r13: 0x000000000000000a r14: 0x20200a3b31203d20 r15: 0x0000000000000000
rip: 0x00007fff90d8114d rfl: 0x0000000000010246 cr2: 0x000000006a86fdc0
Logical CPU: 1
External Modification Summary:
Calls made by other processes targeting this process:
task_for_pid: 11
thread_create: 0
thread_set_state: 0
Calls made by this process:
task_for_pid: 0
thread_create: 0
thread_set_state: 0
Calls made by all processes on this machine:
task_for_pid: 4860
thread_create: 1
thread_set_state: 0
VM Region Summary:
ReadOnly portion of Libraries: Total=211.3M resident=105.4M(50%) swapped_out_or_unallocated=105.9M(50%)
Writable regions: Total=48.2M written=3504K(7%) resident=19.3M(40%) swapped_out=1856K(4%) unallocated=29.0M(60%)
REGION TYPE VIRTUAL
=========== =======
CG backing stores 8K
CG raster data 64K
CG shared images 168K
CoreGraphics 16K
CoreServices 2004K
MALLOC 22.0M
MALLOC guard page 32K
Memory tag=240 4K
Memory tag=242 12K
Memory tag=243 16K
Memory tag=249 156K
STACK GUARD 56.0M
Stack 9820K
VM_ALLOCATE 16.1M
__CI_BITMAP 80K
__DATA 21.8M
__IMAGE 1256K
__LINKEDIT 47.6M
__RC_CAMERAS 236K
__TEXT 163.7M
__UNICODE 544K
mapped file 17.1M
shared memory 312K
=========== =======
TOTAL 358.7M

The most common mistake: NSAppleScript can only be used in the main app thread because it shares a AppleScript ComponentInstance. But if you show up crash log it helps.

You need to set error to nil initially:
NSDictionary *error = nil;
[script executeAndReturnError:&error] will change the value of error only if it fails. That's why you get a bad access if there's no error.

Related

macOS app works fine in Mojave but crashes in Catalina Beta version

I was trying to test app that works fine on Mojave but keeps crashing on Catalina. I am providing the crash details below for any help.What could be the reason for it to not work on Catalina?
I was trying to test app that works fine on Mojave but keeps crashing on Catalina. I am providing the crash details below for any help.What could be the reason for it to not work on Catalina?
Process: SSWatcher [9887]
Path: /Library/Application Support/safe/MacOS/SSWatcher
Identifier: com.safe.sswatcher
Version: 1.0
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: SSWatcher [9887]
User ID: 501
Date/Time: 2019-09-18 16:02:08.870 +0800
OS Version: Mac OS X 10.15 (19A558d)
Report Version: 12
Anonymous UUID: 75520E05-90C3-B100-E7E3-3AE1B6910181
Sleep/Wake UUID: 551DFEAF-E97E-42BB-9610-A525913A821B
Time Awake Since Boot: 6900 seconds
Time Since Wake: 4600 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
terminating with uncaught exception of type NSException
abort() called
Application Specific Backtrace 1:
0 CoreFoundation 0x00007fff396d8033 __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff6f6e6bd4 objc_exception_throw + 48
2 CoreFoundation 0x00007fff3979adda _CFThrowFormattedException + 202
3 CoreFoundation 0x00007fff39798dc0 -[__NSArrayM insertObject:atIndex:].cold.2 + 0
4 CoreFoundation 0x00007fff39618811 -[__NSArrayM insertObject:atIndex:] + 1255
5 SSWatcher 0x000000010d1a5314 -[DNCurrentWindow SetFrontMostWindow] + 1540
6 SSWatcher 0x000000010d1a3e15 _Z29InstallSSWatcherEventHandlersv + 85
7 SSWatcher 0x000000010d1a9111 -[DNMainController awakeFromNib] + 545
8 CoreFoundation 0x00007fff3968d735 -[NSSet makeObjectsPerformSelector:] + 231
9 AppKit 0x00007fff36855e8c -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1485
10 AppKit 0x00007fff36853eaf loadNib + 401
11 AppKit 0x00007fff3685345e +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 693
12 AppKit 0x00007fff368530b4 -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 201
13 AppKit 0x00007fff36852e8d +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 446
14 AppKit 0x00007fff368490b6 NSApplicationMain + 505
15 SSWatcher 0x000000010d1a37e2 main + 34
16 libdyld.dylib 0x00007fff70a452a5 start + 1
17 ??? 0x0000000000000001 0x0 + 1
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff70b942aa __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff70c51707 pthread_kill + 384
2 libsystem_c.dylib 0x00007fff70b1ca08 abort + 120
3 libc++abi.dylib 0x00007fff6dbe8bc8 abort_message + 231
4 libc++abi.dylib 0x00007fff6dbe8d7c demangling_terminate_handler() + 262
5 libobjc.A.dylib 0x00007fff6f6e8aaa _objc_terminate() + 96
6 libc++abi.dylib 0x00007fff6dbf5da7 std::__terminate(void (*)()) + 8
7 libc++abi.dylib 0x00007fff6dbf5b55 __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 27
8 libc++abi.dylib 0x00007fff6dbe734f __cxa_throw + 113
9 libobjc.A.dylib 0x00007fff6f6e6d02 objc_exception_throw + 350
10 com.apple.CoreFoundation 0x00007fff3979adda _CFThrowFormattedException + 202
11 com.apple.CoreFoundation 0x00007fff39798dc0 -[__NSArrayM insertObject:atIndex:].cold.1 + 35
12 com.apple.CoreFoundation 0x00007fff39618811 -[__NSArrayM insertObject:atIndex:] + 1255
13 com.esafe.sswatcher 0x000000010d1a5314 -[DNCurrentWindow SetFrontMostWindow] + 1540
14 com.esafe.sswatcher 0x000000010d1a3e15 InstallSSWatcherEventHandlers() + 85
15 com.esafe.sswatcher 0x000000010d1a9111 -[DNMainController awakeFromNib] + 545
16 com.apple.CoreFoundation 0x00007fff3968d735 -[NSSet makeObjectsPerformSelector:] + 231
17 com.apple.AppKit 0x00007fff36855e8c -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1485
18 com.apple.AppKit 0x00007fff36853eaf loadNib + 401
19 com.apple.AppKit 0x00007fff3685345e +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 693
20 com.apple.AppKit 0x00007fff368530b4 -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 201
21 com.apple.AppKit 0x00007fff36852e8d +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 446
22 com.apple.AppKit 0x00007fff368490b6 NSApplicationMain + 505
23 com.esafe.sswatcher 0x000000010d1a37e2 main + 34
24 libdyld.dylib 0x00007fff70a452a5 start + 1
Thread 1:
0 libsystem_pthread.dylib 0x00007fff70c4e5b4 start_wqthread + 0
Thread 2:
0 libsystem_pthread.dylib 0x00007fff70c4e5b4 start_wqthread + 0
Thread 3:
0 libsystem_pthread.dylib 0x00007fff70c4e5b4 start_wqthread + 0
Thread 4:
0 libsystem_pthread.dylib 0x00007fff70c4e5b4 start_wqthread + 0
Thread 0 crashed with X86 Thread State (64-bit):
rax: 0x0000000000000000 rbx: 0x0000000118023d40 rcx: 0x00007ffee2a5b8f8 rdx: 0x0000000000000000
rdi: 0x0000000000000307 rsi: 0x0000000000000006 rbp: 0x00007ffee2a5b920 rsp: 0x00007ffee2a5b8f8
r8: 0x00007ffee2a5b7c0 r9: 0x00007ffee2a5b990 r10: 0x0000000000000000 r11: 0x0000000000000246
r12: 0x0000000000000307 r13: 0x0000003000000008 r14: 0x0000000000000006 r15: 0x0000000000000016
rip: 0x00007fff70b942aa rfl: 0x0000000000000246 cr2: 0x00007fff9d6a7628
Logical CPU: 0
Error Code: 0x02000148
Trap Number: 133
Hope the details are enough

NSUserDefaults integerForKey EXC_BAD_ACCESS?

I'm using NSUserDefaults in my application. I received quite a lot crash reports with code that crashes on
[[NSUserDefaults standardUserDefaults] integerForKey:MY_KEY];
with EXC_BAD_ACCESS.
Constants are defined in separate .h header files.
static NSString *const MY_KEY = #"myKey";
static NSInteger const SOME_VALUE = 0;
Part of controller method that crashes
- (void)displayData:(NSInteger)param {
NSString *string1;
NSString *string2;
NSInteger value = [[NSUserDefaults standardUserDefaults] integerForKey: MY_KEY];
}
This is the crash report in Xcode Organizer
This is the crash log
Incident Identifier: 1DD7D3CD-DE9B-4623-AB02-06D2365728DA
CrashReporter Key: 020e241bb4242d3e055b3eef0f3ab86f54af59df
Hardware Model: iPhone6,2
Process: My App [194]
Path: /private/var/mobile/Containers/Bundle/Application/31286A32-F4D3-48E1-8B05-ECE119EA96A8/MyApp.app/My App
Identifier: com.mycompany.myapp
Version: 1.0.0 (1.0.0)
Code Type: ARM-64 (Native)
Parent Process: launchd [1]
Date/Time: 2016-01-16 12:55:34.34 +0200
Launch Time: 2016-01-16 12:24:31.31 +0200
OS Version: iOS 9.2 (13C75)
Report Version: 105
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000000158b6560
Triggered by Thread: 0
Filtered syslog:
None found
Global Trace Buffer (reverse chronological seconds):
1.629540 CFNetwork 0x00000001851af104 TCP Conn 0x15a473640 complete. fd: 8, err: 0
1.629540 CFNetwork 0x00000001851b0630 TCP Conn 0x15a473640 event 1. err: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x00000001841b5bd0 objc_msgSend + 16
1 CoreFoundation 0x0000000184b69118 __CFBasicHashAddValue + 328
2 CoreFoundation 0x0000000184a179d8 CFBasicHashAddValue + 288
3 CoreFoundation 0x0000000184a18c90 CFDictionaryAddValue + 248
4 CoreFoundation 0x0000000184a305a8 __CFDictionaryApplyFunction_block_invoke + 24
5 CoreFoundation 0x0000000184a189bc CFBasicHashApply + 128
6 CoreFoundation 0x0000000184a21d3c CFDictionaryApplyFunction + 200
7 CoreFoundation 0x0000000184abd8a8 -[CFPrefsPlistSource mergeIntoDictionary:] + 304
8 CoreFoundation 0x0000000184ae45e0 -[CFPrefsSearchListSource alreadylocked_copyDictionary] + 828
9 CoreFoundation 0x0000000184ae33fc -[CFPrefsSearchListSource alreadylocked_copyValueForKey:] + 72
10 CoreFoundation 0x0000000184b74ee4 ___CFPreferencesCopyAppValueWithContainer_block_invoke + 68
11 CoreFoundation 0x0000000184ae25b8 +[CFPrefsSearchListSource withSearchListForIdentifier:container:perform:] + 572
12 CoreFoundation 0x0000000184b74e5c _CFPreferencesCopyAppValueWithContainer + 188
13 CoreFoundation 0x0000000184b75130 _CFPreferencesGetAppIntegerValueWithContainer + 28
14 My App 0x000000010006f520 -[MyController displayData:] (MyController.m:998)
15 Foundation 0x0000000185425844 -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] + 988
16 Foundation 0x00000001854296a0 -[NSObject(NSThreadPerformAdditions) performSelectorOnMainThread:withObject:waitUntilDone:] + 144
17 My App 0x000000010006cd68 -[MyController StateDidChange:] (MyController.m:307)
18 Foundation 0x00000001854f7e20 __NSThreadPerformPerform + 340
19 CoreFoundation 0x0000000184aecefc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
20 CoreFoundation 0x0000000184aec990 __CFRunLoopDoSources0 + 540
21 CoreFoundation 0x0000000184aea690 __CFRunLoopRun + 724
22 CoreFoundation 0x0000000184a19680 CFRunLoopRunSpecific + 384
23 GraphicsServices 0x0000000185f28088 GSEventRunModal + 180
24 UIKit 0x0000000189890d90 UIApplicationMain + 204
25 My App 0x000000010006b6b4 main (main.m:16)
26 libdyld.dylib 0x00000001845ba8b8 start + 4
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x00000001846d94fc kevent_qos + 8
1 libdispatch.dylib 0x000000018459c94c _dispatch_mgr_invoke + 232
2 libdispatch.dylib 0x000000018458b7bc _dispatch_source_invoke + 0
Thread 2 name: com.apple.NSURLConnectionLoader
Thread 2:
0 libsystem_kernel.dylib 0x00000001846bd4bc mach_msg_trap + 8
1 libsystem_kernel.dylib 0x00000001846bd338 mach_msg + 72
2 CoreFoundation 0x0000000184aecac0 __CFRunLoopServiceMachPort + 196
3 CoreFoundation 0x0000000184aea7c4 __CFRunLoopRun + 1032
4 CoreFoundation 0x0000000184a19680 CFRunLoopRunSpecific + 384
5 CFNetwork 0x0000000185189434 +[NSURLConnection(Loader) _resourceLoadLoop:] + 412
6 Foundation 0x00000001854f7c40 __NSThread__start__ + 1000
7 libsystem_pthread.dylib 0x000000018479fb28 _pthread_body + 156
8 libsystem_pthread.dylib 0x000000018479fa8c _pthread_body + 0
9 libsystem_pthread.dylib 0x000000018479d028 thread_start + 4
Thread 3 name: com.apple.CFSocket.private
Thread 3:
0 libsystem_kernel.dylib 0x00000001846d8368 __select + 8
1 CoreFoundation 0x0000000184af3028 __CFSocketManager + 648
2 libsystem_pthread.dylib 0x000000018479fb28 _pthread_body + 156
3 libsystem_pthread.dylib 0x000000018479fa8c _pthread_body + 0
4 libsystem_pthread.dylib 0x000000018479d028 thread_start + 4
Thread 4 name: NetworkLoad
Thread 4:
0 libsystem_kernel.dylib 0x00000001846bd4bc mach_msg_trap + 8
1 libsystem_kernel.dylib 0x00000001846bd338 mach_msg + 72
2 CoreFoundation 0x0000000184aecac0 __CFRunLoopServiceMachPort + 196
3 CoreFoundation 0x0000000184aea7c4 __CFRunLoopRun + 1032
4 CoreFoundation 0x0000000184a19680 CFRunLoopRunSpecific + 384
5 GeoServices 0x000000018b1e9b5c _runNetworkThread + 428
6 libsystem_pthread.dylib 0x000000018479fb28 _pthread_body + 156
7 libsystem_pthread.dylib 0x000000018479fa8c _pthread_body + 0
8 libsystem_pthread.dylib 0x000000018479d028 thread_start + 4
Thread 5:
0 libsystem_kernel.dylib 0x00000001846d8b6c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x000000018479d530 _pthread_wqthread + 1284
2 libsystem_pthread.dylib 0x000000018479d020 start_wqthread + 4
Thread 6:
0 libsystem_kernel.dylib 0x00000001846d8b6c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x000000018479d530 _pthread_wqthread + 1284
2 libsystem_pthread.dylib 0x000000018479d020 start_wqthread + 4
Thread 7:
0 libsystem_kernel.dylib 0x00000001846d8b6c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x000000018479d530 _pthread_wqthread + 1284
2 libsystem_pthread.dylib 0x000000018479d020 start_wqthread + 4
Thread 8:
0 libsystem_kernel.dylib 0x00000001846d8b6c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x000000018479d530 _pthread_wqthread + 1284
2 libsystem_pthread.dylib 0x000000018479d020 start_wqthread + 4
Thread 9:
0 libsystem_kernel.dylib 0x00000001846d7f48 __psynch_cvwait + 8
1 libsystem_pthread.dylib 0x000000018479ece8 _pthread_cond_wait + 648
2 Foundation 0x0000000185462bac -[NSCondition wait] + 240
3 Foundation 0x0000000185425780 -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] + 792
4 Foundation 0x00000001854296a0 -[NSObject(NSThreadPerformAdditions) performSelectorOnMainThread:withObject:waitUntilDone:] + 144
5 My App 0x0000000100085714 -[AppStateManager HandleAsynchRequest:] (AppStateManager.m:328)
6 Foundation 0x00000001854f7c40 __NSThread__start__ + 1000
7 libsystem_pthread.dylib 0x000000018479fb28 _pthread_body + 156
8 libsystem_pthread.dylib 0x000000018479fa8c _pthread_body + 0
9 libsystem_pthread.dylib 0x000000018479d028 thread_start + 4
Thread 0 crashed with ARM Thread State (64-bit):
x0: 0x0000000155616b10 x1: 0x000000018a206102 x2: 0x00000001556169c0 x3: 0x0000000155616b10
x4: 0x000000015680c2c0 x5: 0x0000000000000010 x6: 0x0000000000000067 x7: 0x0000000000000fd0
x8: 0x00000001a1223000 x9: 0x00000000158b6550 x10: 0x00000001a216a000 x11: 0x00000001a216a000
x12: 0x00000001556169d0 x13: 0x10000000158b6554 x14: 0x000000000000008c x15: 0x00000001556169dd
x16: 0x5000f8d3b4fb11e2 x17: 0x00000001556169dd x18: 0x0000000000000000 x19: 0x000000015680c240
x20: 0x00000001556169c0 x21: 0x0000000155616b10 x22: 0x0000000000000001 x23: 0x00000001a2165360
x24: 0x0000000184aee6c8 x25: 0x00000001a2165360 x26: 0x0000000000000003 x27: 0x0000000158ffa300
x28: 0x00000000a7baadb1 fp: 0x000000016fd99f50 lr: 0x0000000184b69118
sp: 0x000000016fd99f00 pc: 0x00000001841b5bd0 cpsr: 0x20000000
I'm getting this message with zombies enabled
[CFString retain]: message sent to deallocated instance 0x12f78f7e0
I replicated this bug once on my development iPhone. Also note that the application uses real-time TCP communication. When I receive some data a block is created to show the data in the UI.
Can NSUserDefaults produce a EXC_BAD_ACCESS?
It's an issue related to memory leaks. To solve the problem use Xcode static analysis to find potential memory leaks in the code. Also run Xcode instruments with Leaks configuration.

Crash in background- Sprite-Kit related

As the title says- my Sprite Kit game crashes every now and then in background, always with this error-
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000001
Triggered by Thread: 0
Thread 0 Crashed:
0 libGPUSupportMercury.dylib 0x3220193a gpus_ReturnNotPermittedKillClient + 10
1 libGPUSupportMercury.dylib 0x322023d4 gpusSubmitDataBuffers + 100
2 IMGSGX543RC2GLDriver 0x2c6211c4 SubmitPackets + 120
3 GLEngine 0x2fb3bcda gliPresentViewES + 162
4 OpenGLES 0x2fb46134 -[EAGLContext presentRenderbuffer:] + 60
5 SpriteKit 0x2ffb0060 -[SKView _renderContent] + 1216
6 libdispatch.dylib 0x381120ec _dispatch_client_callout + 20
7 libdispatch.dylib 0x381168f6 _dispatch_barrier_sync_f_invoke + 22
8 SpriteKit 0x2ffafb6e -[SKView renderContent] + 78
9 SpriteKit 0x2ffad516 __29-[SKView setUpRenderCallback]_block_invoke + 126
10 SpriteKit 0x2ffcfc84 -[SKDisplayLink _callbackForNextFrame:] + 252
11 QuartzCore 0x2fd9003e CA::Display::DisplayLinkItem::dispatch() + 94
12 QuartzCore 0x2fd8fde8 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 340
13 IOMobileFramebuffer 0x329b876a IOMobileFramebufferVsyncNotifyFunc + 102
14 IOKit 0x2e614e6a IODispatchCalloutFromCFMessage + 246
15 CoreFoundation 0x2d8f2b86 __CFMachPortPerform + 134
16 CoreFoundation 0x2d8fd77c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
17 CoreFoundation 0x2d8fd716 __CFRunLoopDoSource1 + 342
18 CoreFoundation 0x2d8fbee2 __CFRunLoopRun + 1402
19 CoreFoundation 0x2d86653c CFRunLoopRunSpecific + 520
20 CoreFoundation 0x2d86631e CFRunLoopRunInMode + 102
21 GraphicsServices 0x3259d2e6 GSEventRunModal + 134
22 UIKit 0x3011d1e0 UIApplicationMain + 1132
23 NoCar7 0x0010c186 0xf9000 + 78214
24 libdyld.dylib 0x38126ab4 start + 0
Thread 1:
0 libsystem_kernel.dylib 0x381ca838 kevent64 + 24
1 libdispatch.dylib 0x381190d0 _dispatch_mgr_invoke + 228
2 libdispatch.dylib 0x3811363e _dispatch_mgr_thread + 34
Thread 2:
0 libsystem_kernel.dylib 0x381ddc7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x38241e06 _pthread_wqthread + 306
2 libsystem_pthread.dylib 0x38241cc0 start_wqthread + 4
Thread 3:
0 libsystem_kernel.dylib 0x381ddc7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x38241e06 _pthread_wqthread + 306
2 libsystem_pthread.dylib 0x38241cc0 start_wqthread + 4
Thread 4:
0 libsystem_kernel.dylib 0x381ddc7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x38241e06 _pthread_wqthread + 306
2 libsystem_pthread.dylib 0x38241cc0 start_wqthread + 4
Thread 5:
0 libsystem_kernel.dylib 0x381caa84 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x381ca87c mach_msg + 36
2 AudioToolbox 0x2d26d99c AURemoteIO::IOThread::Run() + 184
3 AudioToolbox 0x2d271438 AURemoteIO::IOThread::Entry(void*) + 4
4 AudioToolbox 0x2d19f2ac CAPThread::Entry(CAPThread*) + 208
5 libsystem_pthread.dylib 0x38243c5a _pthread_body + 138
6 libsystem_pthread.dylib 0x38243bca _pthread_start + 98
7 libsystem_pthread.dylib 0x38241ccc thread_start + 4
Thread 0 crashed with ARM Thread State (32-bit):
r0: 0xdeadbeef r1: 0x00000001 r2: 0x1b48d000 r3: 0x00000044
r4: 0x00000000 r5: 0x04e5d560 r6: 0x04e5d438 r7: 0x27d088c0
r8: 0x00000000 r9: 0x00000fff r10: 0x04e5d000 r11: 0x04e5b90f
ip: 0x3a004114 sp: 0x27d088a0 lr: 0x322023d9 pc: 0x3220193a
cpsr: 0x20000030
What can cause it?
The problem can be caused by audio, if so you can check the answer here https://stackoverflow.com/a/19283721/1278463
I solved this in a game which is not using audio. Th solution is to pause SKView when entering background:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
SKView *view = (SKView *)self.window.rootViewController.view;
if (view) {
view.paused = YES;
}
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
SKView *view = (SKView *)self.window.rootViewController.view;
if (view) {
view.paused = NO;
}
}
For me, pausing the SKView and using [[SKView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)] instead of [[SKView alloc] init] solve the issue !
[[SKView alloc] init] seems to be bugged !
It's most likely a bug within SpriteKit. Check out this thread for a solution: SpriteKit- the right way to multitask

Retain property and EXC_BAD_ACCESS on NSArray

I have gone through all the relevant posts on EXC_BAD_ACCESS but failed to have the concept clear yet. Maybe I should first work on learning the basic concepts but right now I need to get on this issue.. So, stepped in to get some expert help..
Here is my code (I have pasted only the relevant part)
//In .h
//=====
#interface GUIMainController : GUIController {
::
::
NSArray* shufflePositionArray;
}
#property (retain)NSArray* shufflePositionArray;
//In .mm
//=======
#synthesize shufflePositionArray;
-(void)start
{
::
NSString* shufflePositionArrayPlistPath=nil;
NSString* shufflePositionArrayPlistPathFromConfiguration=
#"/MyApp/Configuration/ShufflePositionArray.plist";
if ([[NSFileMngrdfltMngr]fileExistsAtPath:shufflePositionArrayPlistPathFromConfig])
{
self.shufflePositionArray=
[NSArrayarrayWithContentsOfFile:shufflePositionArrayPlistPathFromConfig];
}
if (self.shufflePositionArray==nil) {
shufflePositionArrayPlistPath=
[thisBundle pathForResource:#"ShufflePositionArray" ofType:#"plist"];
if (shufflePositionArrayPlistPath!=nil) {
self.shufflePositionArray=
[NSArray arrayWithContentsOfFile:shufflePositionArrayPlistPath];
}
}
}
//From another method:
//====================
-(void)shuffleWindow
{
::
if (shufflePositionArray!=nil && [self.shufflePositionArray count]!=0){
:: // some code
if (shufflePositionArray!=nil && [self.shufflePositionArray count]!=0){
::
:: // some code
processwindowlocation_=(processwindowlocation_+1)%[self.shufflePositionArray count];
// ######## there is a crash here !!!!!! #############
}
}
}
//And then..we release it here:
//==============================
-(void)dealloc {
if(shufflePositionArray!=nil){
[shufflePositionArray release];
}
[super dealloc];
}
I am completely new to obj-C, any sort of help would be appreciated.
Thanks in advance.
Here is the crash:
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000018
VM Regions Near 0x18:
-->
__TEXT 000000010d89a000-000000010d927000 [ 564K] r-x/rwx SM=COW /Ihome/MyAppCE.app/Contents/MacOS/MyAppCE
Application Specific Information:
objc_msgSend() selector name: count
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff82c5d62f objc_msgSend_vtable9 + 47
1 com.apple.AppKit 0x00007fff88842b05 +[NSScreen screens] + 847
2 com.apple.AppKit 0x00007fff88844575 +[NSScreen _zeroScreenHeight] + 44
3 com.apple.AppKit 0x00007fff888b15cf _NSShapeRoundedWindowWithWeighting + 61
4 com.apple.AppKit 0x00007fff888507c3 -[NSThemeFrame shapeWindow] + 336
5 com.apple.AppKit 0x00007fff888b055c -[NSThemeFrame setFrameSize:] + 457
6 com.apple.AppKit 0x00007fff888af68f -[NSWindow _setFrame:updateBorderViewSize:] + 929
7 com.apple.AppKit 0x00007fff888aee04 -[NSWindow _oldPlaceWindow:] + 1142
8 com.apple.AppKit 0x00007fff888ae2b9 -[NSWindow _setFrameCommon:display:stashSize:] + 1837
9 com.Apple.Phoenix.UI 0x0000000110580045 -[GUIMainController shuffleWindow] + 1477 (GUIMainController.mm:470)
10 com.Apple.Phoenix.UI 0x0000000110586aef -[GUIPeriodicController periodic:] + 2399 (GUIPeriodicController.mm:219)
11 com.apple.Foundation 0x00007fff86867463 __NSFireTimer + 96
12 com.apple.CoreFoundation 0x00007fff81df5804 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
13 com.apple.CoreFoundation 0x00007fff81df531d __CFRunLoopDoTimer + 557
14 com.apple.CoreFoundation 0x00007fff81ddaad9 __CFRunLoopRun + 1529
15 com.apple.CoreFoundation 0x00007fff81dda0e2 CFRunLoopRunSpecific + 290
16 com.apple.HIToolbox 0x00007fff83dc6eb4 RunCurrentEventLoopInMode + 209
17 com.apple.HIToolbox 0x00007fff83dc6b94 ReceiveNextEventCommon + 166
18 com.apple.HIToolbox 0x00007fff83dc6ae3 BlockUntilNextEventMatchingListInMode + 62
19 com.apple.AppKit 0x00007fff8887f533 _DPSNextEvent + 685
20 com.apple.AppKit 0x00007fff8887edf2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
21 com.Apple.Phoenix.UI 0x0000000110594b52 processUIEvent() + 290 (PhoenixCECocoaGUI.mm:363)
22 com.Apple.Phoenix.UI 0x000000011058e152 Phoenix::Core::UICocoaImpl::processEvent() + 44 (UICocoaImpl.mm:61)
23 com.Apple.MyAppCE 0x000000010d8ae62e main + 2302 (mainer.cpp:180)
24 com.Apple.MyAppCE 0x000000010d89b604 start + 52
Thread 0 crashed with X86 Thread State (64-bit):
rax: 0x000000000000000f rbx: 0xffffffffffffffff rcx: 0x0000000001010101 rdx: 0x0000000000000001
rdi: 0xffffffffffffffff rsi: 0x00007fff7268ea80 rbp: 0x00007fff523631b0 rsp: 0x00007fff52363028
r8: 0x00007fff72435a30 r9: 0x00007fff72435a01 r10: 0x0000000000000000 r11: 0x00007f968c000600
r12: 0x0000000000000000 r13: 0x0000000000000000 r14: 0x0000000000000001 r15: 0x000000000000000c
rip: 0x00007fff82c5d62f rfl: 0x0000000000010206 cr2: 0x0000000000000018
If you have a crash, post the backtrace.
Assuming you haven't cut out some relevant code, the only way that processwindowlocation_=(processwindowlocation_+1)%[self.shufflePositionArray count]; could crash (assuming that that is actually the line of the crash) is if either self is invalid or the shufflePositionArray is invalid.
Note that invalid does not mean nil; nil would just return 0 for the count.
Note, also, that the check for non-nil here is pointless:
if(shufflePositionArray!=nil){
[shufflePositionArray release];
}
That crash is odd. I wouldn't really expect a crash there given your code.
Try turning on Zombie detection (Instruments -- Google can find more info, if you need) and seeing if it is an over-release issue.

NSTextField binding causes EXC_BAD_ACCESS

I have an NSTextField which is bound to an int in an object that I have included in my nib. When the object changes its int, the text field follows suit, and everything looks fine.
However, when I try to change it manually the program crashes as soon as I hit a key. It's not even getting into my setter methods, it just crashes with
Program received signal: “EXC_BAD_ACCESS”.
It's not even in any of my code... presumably, I made the binding wrong, but what could I have done that would make it segfault like that?
ETA: stackframes from a crash:
Process: DocKeep [77998]
Path: /Users/acordex/Documents/projects/DocKeep/build/Debug/DocKeep.app/Contents/MacOS/DocKeep
Identifier: com.acordex.DocKeep
Version: 9.00 pre-Alpha (9.00 pre-Alpha)
Code Type: X86 (Native)
Parent Process: Instruments [77954]
Date/Time: 2010-07-29 10:01:11.927 -0400
OS Version: Mac OS X 10.6.4 (10F569)
Report Version: 6
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x000000000000001c
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 com.apple.AppKit 0x954a4734 -[NSDocument(NSEditorRegistration) _isBeingEdited] + 24
1 com.apple.AppKit 0x954a4707 -[NSDocument isDocumentEdited] + 47
2 com.apple.AppKit 0x955b3900 -[NSDocument(NSEditorRegistration) objectDidBeginEditing:] + 48
3 com.apple.AppKit 0x95461ef9 -[NSValueBinder _startChanging] + 126
4 com.apple.AppKit 0x95461dc1 -[NSTextValueBinder _startChanging] + 60
5 com.apple.AppKit 0x95461d5f -[_NSBindingAdaptor _editor:didChangeEditingState:bindingAdaptor:] + 181
6 com.apple.AppKit 0x95461c9f -[_NSBindingAdaptor editorDidBeginEditing:] + 278
7 com.apple.AppKit 0x95442e5a -[NSTextField textShouldBeginEditing:] + 239
8 com.apple.AppKit 0x95441d0b -[NSTextView(NSSharing) shouldChangeTextInRanges:replacementStrings:] + 573
9 com.apple.AppKit 0x95464563 _NSDoUserReplaceForCharRange + 191
10 com.apple.AppKit 0x9546449e _NSDoUserDeleteForCharRange + 79
11 com.apple.AppKit 0x95463b07 -[NSTextView(NSKeyBindingCommands) deleteBackward:] + 684
12 com.apple.AppKit 0x9544b364 -[NSResponder doCommandBySelector:] + 77
13 com.apple.AppKit 0x9544ac7f -[NSTextView doCommandBySelector:] + 240
14 com.apple.AppKit 0x95439bbf -[NSKeyBindingManager(NSKeyBindingManager_MultiClients) interpretEventAsCommand:forClient:] + 1911
15 com.apple.AppKit 0x9543d44f -[NSTextInputContext handleEvent:] + 1604
16 com.apple.AppKit 0x95439229 -[NSView interpretKeyEvents:] + 209
17 com.apple.AppKit 0x9543ccd5 -[NSTextView keyDown:] + 751
18 com.apple.AppKit 0x9536df6c -[NSWindow sendEvent:] + 5757
19 com.apple.AppKit 0x95286aff -[NSApplication sendEvent:] + 6431
20 com.apple.AppKit 0x9521a5bb -[NSApplication run] + 917
21 com.apple.AppKit 0x952125ed NSApplicationMain + 574
22 com.acordex.DocKeep 0x0000224c main + 30 (main.m:14)
23 com.acordex.DocKeep 0x00002202 start + 54
Thread 1:
0 libSystem.B.dylib 0x94a319d2 __workq_kernreturn + 10
1 libSystem.B.dylib 0x94a31f68 _pthread_wqthread + 941
2 libSystem.B.dylib 0x94a31b86 start_wqthread + 30
Thread 2: Dispatch queue: com.apple.libdispatch-manager
0 libSystem.B.dylib 0x94a32942 kevent + 10
1 libSystem.B.dylib 0x94a3305c _dispatch_mgr_invoke + 215
2 libSystem.B.dylib 0x94a32519 _dispatch_queue_invoke + 163
3 libSystem.B.dylib 0x94a322be _dispatch_worker_thread2 + 240
4 libSystem.B.dylib 0x94a31d41 _pthread_wqthread + 390
5 libSystem.B.dylib 0x94a31b86 start_wqthread + 30
Thread 3:
0 libSystem.B.dylib 0x94a3a066 __semwait_signal + 10
1 libSystem.B.dylib 0x94a39d22 _pthread_cond_wait + 1191
2 libSystem.B.dylib 0x94a3b9b8 pthread_cond_wait$UNIX2003 + 73
3 com.apple.CoreVideo 0x96730c3e CVDisplayLink::runIOThread() + 1016
4 com.apple.CoreVideo 0x9673082a startIOThread(void*) + 156
5 libSystem.B.dylib 0x94a3981d _pthread_start + 345
6 libSystem.B.dylib 0x94a396a2 thread_start + 34
Thread 0 crashed with X86 Thread State (32-bit):
eax: 0x00000000 ebx: 0x954a472d ecx: 0x00000001 edx: 0x00000000
edi: 0x0045f650 esi: 0x0045f650 ebp: 0xbfffe738 esp: 0xbfffe720
ss: 0x0000001f efl: 0x00010282 eip: 0x954a4734 cs: 0x00000017
ds: 0x0000001f es: 0x0000001f fs: 0x00000000 gs: 0x00000037
cr2: 0x0000001c
I DO have a document class that is subclassed off of NSDocument, and the textfield IS bound to a field of that document object, but I'm not sure why that would matter.
The environment variable NSBindingDebugLogLevel might be useful. Set it and check your logs carefully for warnings. You might not see the warning if you have a breakpoint set on NSException raise.
Bindings should work with an int, definitely not with an unsigned int. But NSTextfield requires an NSString, or at least an NSNumber and an associated NSNumberFormatter.