iPhone崩溃可能与NSUserDefaults有关

时间:2014-11-12 13:04:53

标签: xcode cocoa-touch crash nsuserdefaults

新信息:我已在手机连接到计算机时复制了崩溃,并启用了异常断点,此时应用程序暂停。如果有人想在我停止应用程序之前帮助我获取相关信息,那将会很棒。它阻止了我在一条线上创造了一个我几周来一直没有问题的声音,这令人困惑。

我最近在我的游戏中实施了NSUserDefaults,并且它已经导致崩溃。问题是,当它连接到我的计算机时它永远不会崩溃所以我无法抓住崩溃 - 我只是假设它与NSUserDefaults有关。

截至目前,我只在我的NSUserDefaults中存储了Ints。我今天早上意识到我还没有使用synchronize电话,这会导致崩溃吗?

另外,如何检查不存在的密钥?

当我点击从游戏菜单切换到实际玩游戏时发生崩溃。游戏场景initWithSize中的第一行代码之一是调用检查和NSLog一些默认值。

新信息:查看崩溃日志后,此崩溃似乎有两个部分。首先,KERN_PROTECTION_FAILURE在我使用它时崩溃应用程序,实际上另一个"崩溃"几分钟后报告,有时我确定我使用该应用程序。

编辑:CRASH LOG 1:

Hardware Model:      iPhone6,1
Process:             Pixel Pilot [28505]
Path:                /var/mobile/Applications/0DD06667-D5BA-4FAA-A5B1-2747054A79A0/Pixel Pilot.app/Pixel Pilot
Identifier:          com.pixelstewdio.Pixel-Pilot
Version:             1.0 (1.0)
Code Type:           ARM-64 (Native)
Parent Process:      launchd [1]

Date/Time:           2014-11-12 07:34:03.272 -0500
OS Version:          iOS 7.1.2 (11D257)
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x000000018516aefa
Triggered by Thread:  0

Thread 0 Crashed:
0   SpriteKit                       0x00000001873ac364 SKCSprite::removeSubsprite(SKCSprite*) + 152
1   SpriteKit                       0x00000001873a0d04 -[SKShapeNode dealloc] + 52
2   libobjc.A.dylib                 0x0000000190a1d470 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 520
3   CoreFoundation                  0x00000001843f9b34 _CFAutoreleasePoolPop + 24
4   UIKit                           0x00000001874b6540 _wrapRunLoopWithAutoreleasePoolHandler + 72
5   CoreFoundation                  0x00000001844bb854 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28
6   CoreFoundation                  0x00000001844b8adc __CFRunLoopDoObservers + 368
7   CoreFoundation                  0x00000001844b8e68 __CFRunLoopRun + 760
8   CoreFoundation                  0x00000001843f9dcc CFRunLoopRunSpecific + 448
9   GraphicsServices                0x000000018a0e1c08 GSEventRunModal + 164
10  UIKit                           0x000000018752afc0 UIApplicationMain + 1152
11  Pixel Pilot                     0x000000010009034c main (main.m:16)
12  libdyld.dylib                   0x0000000190ff7a9c start + 0

Thread 1:
0   libsystem_kernel.dylib          0x00000001910d9aa8 kevent64 + 8
1   libdispatch.dylib               0x0000000190fdd998 _dispatch_mgr_thread + 48

Thread 2:
0   libsystem_kernel.dylib          0x00000001910f2e74 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000191171548 start_wqthread + 0

Thread 3:
0   libsystem_kernel.dylib          0x00000001910f2e74 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000191171548 start_wqthread + 0

Thread 4:
0   libsystem_kernel.dylib          0x00000001910f2e74 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000191171548 start_wqthread + 0

Thread 5:
0   libsystem_kernel.dylib          0x00000001910f2e74 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000191171548 start_wqthread + 0

Thread 6:
0   libsystem_kernel.dylib          0x00000001910d9ca0 mach_msg_trap + 8
1   CoreFoundation                  0x00000001844bad20 __CFRunLoopServiceMachPort + 180
2   CoreFoundation                  0x00000001844b8eb0 __CFRunLoopRun + 832
3   CoreFoundation                  0x00000001843f9dcc CFRunLoopRunSpecific + 448
4   CoreFoundation                  0x000000018444f454 CFRunLoopRun + 108
5   CoreMotion                      0x0000000184bb2538 ___lldb_unnamed_function1441$$CoreMotion + 632
6   libsystem_pthread.dylib         0x0000000191173e18 _pthread_body + 164
7   libsystem_pthread.dylib         0x0000000191173d70 _pthread_start + 136
8   libsystem_pthread.dylib         0x0000000191171550 thread_start + 0

Thread 7:
0   libsystem_kernel.dylib          0x00000001910d9ca0 mach_msg_trap + 8
1   AudioToolbox                    0x0000000183d37040 AURemoteIO::IOThread::Run() + 108
2   AudioToolbox                    0x0000000183d3a234 AURemoteIO::IOThread::Entry(void*) + 8
3   AudioToolbox                    0x0000000183c6a278 CAPThread::Entry(CAPThread*) + 136
4   libsystem_pthread.dylib         0x0000000191173e18 _pthread_body + 164
5   libsystem_pthread.dylib         0x0000000191173d70 _pthread_start + 136
6   libsystem_pthread.dylib         0x0000000191171550 thread_start + 0

Thread 8:
0   libsystem_kernel.dylib          0x00000001910d9ca0 mach_msg_trap + 8
1   CoreFoundation                  0x00000001844bad20 __CFRunLoopServiceMachPort + 180
2   CoreFoundation                  0x00000001844b8eb0 __CFRunLoopRun + 832
3   CoreFoundation                  0x00000001843f9dcc CFRunLoopRunSpecific + 448
4   AudioToolbox                    0x0000000183c79abc GenericRunLoopThread::Entry(void*) + 156
5   AudioToolbox                    0x0000000183c6a278 CAPThread::Entry(CAPThread*) + 136
6   libsystem_pthread.dylib         0x0000000191173e18 _pthread_body + 164
7   libsystem_pthread.dylib         0x0000000191173d70 _pthread_start + 136
8   libsystem_pthread.dylib         0x0000000191171550 thread_start + 0

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x000000012cd11870   x1: 0x000000012cd116d0   x2: 0x0000000000000008   x3: 0x000000019112bcdc
    x4: 0x0000000000000000   x5: 0x0000000000000000   x6: 0x0000000000000000   x7: 0x0000000000000000
    x8: 0x000000018516aee6   x9: 0x00000001915e4ec8  x10: 0x0000000000000067  x11: 0x00000000002c2a00
   x12: 0x0000000000000000  x13: 0x0000000000000000  x14: 0x00000000c1fb8c17  x15: 0x0000000016ed1586
   x16: 0x000000019116d42c  x17: 0x00000001873a0cd0  x18: 0x0000000000000000  x19: 0x000000012cd11500
   x20: 0x000000012cd11870  x21: 0x0000000193ec4380  x22: 0x0000000193ec4380  x23: 0x00000000a1a1a1a1
   x24: 0x0000000193eb0098  x25: 0x000000010012c048  x26: 0xa3a3a3a3a3a3a3a3  x27: 0x000000016fda6cd0
   x28: 0x0000000000000001  fp: 0x000000016fda6780   lr: 0x00000001873ac344
    sp: 0x000000016fda6760   pc: 0x00000001873ac364 cpsr: 0x60000000

CRASH LOG 2:

Hardware Model:      iPhone6,1
Process:             Pixel Pilot [28606]
Path:                /var/mobile/Applications/0DD06667-D5BA-4FAA-A5B1-2747054A79A0/Pixel Pilot.app/Pixel Pilot
Identifier:          com.pixelstewdio.Pixel-Pilot
Version:             1.0 (1.0)
Code Type:           ARM-64 (Native)
Parent Process:      launchd [1]

Date/Time:           2014-11-12 07:43:50.305 -0500
OS Version:          iOS 7.1.2 (11D257)
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000001
Triggered by Thread:  0

Thread 0 Crashed:
0   libGPUSupportMercury.dylib      0x0000000189cb46f8 gpus_ReturnNotPermittedKillClient + 12
1   AGXGLDriver                     0x00000001830d3248 SubmitPackets + 196
2   GLEngine                        0x0000000186e3fa78 gliPresentViewES_Exec + 236
3   GLEngine                        0x0000000186e3f908 gliPresentViewES + 192
4   OpenGLES                        0x0000000186e4cc98 -[EAGLContext presentRenderbuffer:] + 76
5   SpriteKit                       0x0000000187389fb8 -[SKView _renderContent] + 1080
6   libdispatch.dylib               0x0000000190fdbfd0 _dispatch_client_callout + 12
7   libdispatch.dylib               0x0000000190fe1c80 _dispatch_barrier_sync_f_invoke + 44
8   SpriteKit                       0x0000000187389b40 -[SKView renderContent] + 96
9   SpriteKit                       0x0000000187387790 __29-[SKView setUpRenderCallback]_block_invoke + 72
10  SpriteKit                       0x00000001873a6a8c -[SKDisplayLink _callbackForNextFrame:] + 284
11  QuartzCore                      0x0000000187100cb8 CA::Display::DisplayLinkItem::dispatch() + 32
12  QuartzCore                      0x0000000187100ac4 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 296
13  IOKit                           0x00000001853fbe70 IODispatchCalloutFromCFMessage + 360
14  CoreFoundation                  0x00000001844aca8c __CFMachPortPerform + 188
15  CoreFoundation                  0x00000001844bb03c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
16  CoreFoundation                  0x00000001844baf9c __CFRunLoopDoSource1 + 440
17  CoreFoundation                  0x00000001844b91c0 __CFRunLoopRun + 1616
18  CoreFoundation                  0x00000001843f9dcc CFRunLoopRunSpecific + 448
19  GraphicsServices                0x000000018a0e1c08 GSEventRunModal + 164
20  UIKit                           0x000000018752afc0 UIApplicationMain + 1152
21  Pixel Pilot                     0x000000010011834c main (main.m:16)
22  libdyld.dylib                   0x0000000190ff7a9c start + 0

Thread 1:
0   libsystem_kernel.dylib          0x00000001910d9aa8 kevent64 + 8
1   libdispatch.dylib               0x0000000190fdd998 _dispatch_mgr_thread + 48

Thread 2:
0   libsystem_kernel.dylib          0x00000001910f2e74 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000191171548 start_wqthread + 0

Thread 3:
0   libsystem_kernel.dylib          0x00000001910f2e74 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000191171548 start_wqthread + 0

Thread 4:
0   libsystem_kernel.dylib          0x00000001910d9ca0 mach_msg_trap + 8
1   CoreFoundation                  0x00000001844bad20 __CFRunLoopServiceMachPort + 180
2   CoreFoundation                  0x00000001844b8eb0 __CFRunLoopRun + 832
3   CoreFoundation                  0x00000001843f9dcc CFRunLoopRunSpecific + 448
4   CoreFoundation                  0x000000018444f454 CFRunLoopRun + 108
5   CoreMotion                      0x0000000184bb2538 ___lldb_unnamed_function1441$$CoreMotion + 632
6   libsystem_pthread.dylib         0x0000000191173e18 _pthread_body + 164
7   libsystem_pthread.dylib         0x0000000191173d70 _pthread_start + 136
8   libsystem_pthread.dylib         0x0000000191171550 thread_start + 0

Thread 5:
0   libsystem_kernel.dylib          0x00000001910d9ca0 mach_msg_trap + 8
1   AudioToolbox                    0x0000000183d37040 AURemoteIO::IOThread::Run() + 108
2   AudioToolbox                    0x0000000183d3a234 AURemoteIO::IOThread::Entry(void*) + 8
3   AudioToolbox                    0x0000000183c6a278 CAPThread::Entry(CAPThread*) + 136
4   libsystem_pthread.dylib         0x0000000191173e18 _pthread_body + 164
5   libsystem_pthread.dylib         0x0000000191173d70 _pthread_start + 136
6   libsystem_pthread.dylib         0x0000000191171550 thread_start + 0

Thread 6:
0   libsystem_kernel.dylib          0x00000001910d9ca0 mach_msg_trap + 8
1   CoreFoundation                  0x00000001844bad20 __CFRunLoopServiceMachPort + 180
2   CoreFoundation                  0x00000001844b8eb0 __CFRunLoopRun + 832
3   CoreFoundation                  0x00000001843f9dcc CFRunLoopRunSpecific + 448
4   AudioToolbox                    0x0000000183c79abc GenericRunLoopThread::Entry(void*) + 156
5   AudioToolbox                    0x0000000183c6a278 CAPThread::Entry(CAPThread*) + 136
6   libsystem_pthread.dylib         0x0000000191173e18 _pthread_body + 164
7   libsystem_pthread.dylib         0x0000000191173d70 _pthread_start + 136
8   libsystem_pthread.dylib         0x0000000191171550 thread_start + 0

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x00000000e00002e2   x2: 0x000000012cd58950   x3: 0x0000000000000030
    x4: 0x0000000000000333   x5: 0x0000000000000000   x6: 0x0000000000000000   x7: 0x0000000000000000
    x8: 0x0000000000000001   x9: 0x00000000deadbeef  x10: 0x0000000000003fff  x11: 0x000000012cd5c000
   x12: 0x000000012cd58000  x13: 0x00000000a190c48e  x14: 0x000000008beb8f17  x15: 0x00000000e6b617dd
   x16: 0x000000019116c3fc  x17: 0x0015a535773a04d9  x18: 0x0000000000000000  x19: 0x000000012f000000
   x20: 0x00000000e00002e2  x21: 0x000000012f00085c  x22: 0x000000010310e043  x23: 0x0000000000000001
   x24: 0x000000000000a050  x25: 0x0000000000000000  x26: 0x0000000000000668  x27: 0x000000000000a6a0
   x28: 0x0000000193eb0098  fp: 0x000000016fd1d890   lr: 0x0000000189cb56ac
    sp: 0x000000016fd1d840   pc: 0x0000000189cb46f8 cpsr: 0x60000000

1 个答案:

答案 0 :(得分:0)

检查NSUserDefault对象是否为null执行此操作:

NSUserDefaults *example = [NSUserDefaults standardUserDefaults];

NSObject * object = [example objectForKey:@"test"];

if(object == nil)
{
    //object is nil
}
else
{
   //object isn't nil
}

然后你需要在NSUserDefault

内做一些事情
[example synchronize];