Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode EXC\u对深NSString stringWithFormat的错误访问:_Xcode_Macos_Nsstring_Exc Bad Access - Fatal编程技术网

Xcode EXC\u对深NSString stringWithFormat的错误访问:

Xcode EXC\u对深NSString stringWithFormat的错误访问:,xcode,macos,nsstring,exc-bad-access,Xcode,Macos,Nsstring,Exc Bad Access,我正在使用Xcode 5.1.1编写一个Mac OS(10.8.4)应用程序,仅供我自己使用(在我陷入困境时解决一个八人纸牌游戏),我不关心效率或内存使用。这是一个递归程序(它创建一个可能的移动树,递归,创建下一个移动,等等),所以它需要大量内存(我有24 GB),并且我增加了堆栈(-Wl,-stack_size,0x4000000)。但是,不管堆栈大小如何,我得到EXC_BAD_ACCESS code=2,始终处于相同的深度(大约170个级别),并且始终位于使用NSString stringW

我正在使用Xcode 5.1.1编写一个Mac OS(10.8.4)应用程序,仅供我自己使用(在我陷入困境时解决一个八人纸牌游戏),我不关心效率或内存使用。这是一个递归程序(它创建一个可能的移动树,递归,创建下一个移动,等等),所以它需要大量内存(我有24 GB),并且我增加了堆栈(-Wl,-stack_size,0x4000000)。但是,不管堆栈大小如何,我得到EXC_BAD_ACCESS code=2,始终处于相同的深度(大约170个级别),并且始终位于使用NSString stringWithFormat的行上:例如:

   NSString *temp = [NSString stringWithFormat:@"%d",value]; // value is an integer
在之前的所有递归级别中,该行都执行得很好。如果删除该特定行,则会在其他stringWithFormat行发生异常。就好像NSString有它自己的限制,不管我的堆栈大小设置如何。当使用垃圾收集而不是ARC时,它就可以工作了。(Xcode希望我转换为ARC。)

我已经检查了僵尸,但是在错误行中没有任何对象被引用

为什么不管堆栈大小,我都会获得EXC_BAD_访问权限,并且总是使用stringWithFormat:

正在添加崩溃日志:

Process:         EightOff Solver [11701]
Path:            /Users/USER/Library/Developer/Xcode/DerivedData/EightOff_Solver-dqppnsumvcsujjflailrgqxogyij/Build/Products/Debug/EightOff Solver.app/Contents/MacOS/EightOff Solver
Identifier:      com.yourcompany.EightOff_Solver
Version:         1.0
Code Type:       X86-64 (Native)
Parent Process:  launchd [179]
User ID:         501

Date/Time:       2014-06-25 01:38:46.581 -0500
OS Version:      Mac OS X 10.8.4 (12E55)
Report Version:  10
Sleep/Wake UUID: 561695D4-0498-43DC-9B0E-9417A5D5120D

Interval Since Last Report:          60266 sec
Crashes Since Last Report:           2
Per-App Crashes Since Last Report:   9
Anonymous UUID:                      96F16B3C-9A73-63C2-B5CD-11CC51CFE612

Crashed Thread:  1  Dispatch queue: com.apple.root.default-priority

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000100400ec8

VM Regions Near 0x100400ec8:
    MALLOC_TINY            0000000100100000-0000000100400000 [ 3072K] rw-/rwx SM=PRV  
--> STACK GUARD            0000000100400000-0000000100401000 [    4K] ---/rwx SM=NUL  stack guard for thread 1
    Stack                  0000000100401000-0000000100483000 [  520K] rw-/rwx SM=COW  thread 1

Thread 0:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff8eb18686 mach_msg_trap + 10
1   libsystem_kernel.dylib          0x00007fff8eb17c42 mach_msg + 70
2   com.apple.CoreFoundation        0x00007fff93d38233 __CFRunLoopServiceMachPort + 195
3   com.apple.CoreFoundation        0x00007fff93d3d916 __CFRunLoopRun + 1078
4   com.apple.CoreFoundation        0x00007fff93d3d0e2 CFRunLoopRunSpecific + 290
5   com.apple.HIToolbox             0x00007fff93a36eb4 RunCurrentEventLoopInMode + 209
6   com.apple.HIToolbox             0x00007fff93a36c52 ReceiveNextEventCommon + 356
7   com.apple.HIToolbox             0x00007fff93a36ae3 BlockUntilNextEventMatchingListInMode + 62
8   com.apple.AppKit                0x00007fff9a52a533 _DPSNextEvent + 685
9   com.apple.AppKit                0x00007fff9a529df2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
10  com.apple.AppKit                0x00007fff9a5211a3 -[NSApplication run] + 517
11  com.apple.AppKit                0x00007fff9a4c5bd6 NSApplicationMain + 869
12  com.yourcompany.EightOff_Solver 0x0000000100006ea2 main + 34 (main.m:13)
13  com.yourcompany.EightOff_Solver 0x0000000100001bc4 start + 52

Thread 1 Crashed:: Dispatch queue: com.apple.root.default-priority
0   libsystem_c.dylib               0x00007fff936c682d __vfprintf + 40
1   libsystem_c.dylib               0x00007fff936c4e16 vsnprintf_l + 254
2   libsystem_c.dylib               0x00007fff936bf462 snprintf_l + 127
3   com.apple.CoreFoundation        0x00007fff93d0ef3f __CFStringAppendFormatCore + 11199
4   com.apple.CoreFoundation        0x00007fff93d594fb _CFStringCreateWithFormatAndArgumentsAux + 107
5   com.apple.Foundation            0x00007fff9a03f13c +[NSString stringWithFormat:] + 170
6   com.yourcompany.EightOff_Solver 0x0000000100009b67 -[Card description] + 663 (Card.m:265)
7   com.yourcompany.EightOff_Solver 0x00000001000091f7 -[Card makeNewGameStates:] + 9031 (Card.m:211)
8   com.yourcompany.EightOff_Solver 0x0000000100005087 -[MyDocument recursiveOnGameState:depth:] + 6903 (MyDocument.m:1195)
9   com.yourcompany.EightOff_Solver 0x00000001000054b2 -[MyDocument recursiveOnGameState:depth:] + 7970 (MyDocument.m:1210)
10  com.yourcompany.EightOff_Solver 0x00000001000054b2 -[MyDocument recursiveOnGameState:depth:] + 7970 (MyDocument.m:1210)

... [deleted identical lines numbered 11 through 170]

171 com.yourcompany.EightOff_Solver 0x00000001000054b2 -[MyDocument recursiveOnGameState:depth:] + 7970 (MyDocument.m:1210)
172 com.yourcompany.EightOff_Solver 0x00000001000054b2 -[MyDocument recursiveOnGameState:depth:] + 7970 (MyDocument.m:1210)
173 com.yourcompany.EightOff_Solver 0x00000001000054b2 -[MyDocument recursiveOnGameState:depth:] + 7970 (MyDocument.m:1210)
174 com.yourcompany.EightOff_Solver 0x00000001000054b2 -[MyDocument recursiveOnGameState:depth:] + 7970 (MyDocument.m:1210)
175 com.yourcompany.EightOff_Solver 0x00000001000054b2 -[MyDocument recursiveOnGameState:depth:] + 7970 (MyDocument.m:1210)
176 com.yourcompany.EightOff_Solver 0x00000001000054b2 -[MyDocument recursiveOnGameState:depth:] + 7970 (MyDocument.m:1210)
177 com.yourcompany.EightOff_Solver 0x00000001000029c2 -[MyDocument startBackgroundThread] + 2706 (MyDocument.m:882)
178 com.apple.CoreFoundation        0x00007fff93d8f09c __invoking___ + 140
179 com.apple.CoreFoundation        0x00007fff93d8ef37 -[NSInvocation invoke] + 263
180 com.apple.Foundation            0x00007fff9a07da30 -[NSInvocationOperation main] + 34
181 com.apple.Foundation            0x00007fff9a075926 -[__NSOperationInternal start] + 684
182 com.apple.Foundation            0x00007fff9a07d0f1 __block_global_6 + 129
183 libdispatch.dylib               0x00007fff96ec4f01 _dispatch_call_block_and_release + 15
184 libdispatch.dylib               0x00007fff96ec10b6 _dispatch_client_callout + 8
185 libdispatch.dylib               0x00007fff96ec21fa _dispatch_worker_thread2 + 304
186 libsystem_c.dylib               0x00007fff93654d0b _pthread_wqthread + 404
187 libsystem_c.dylib               0x00007fff9363f1d1 start_wqthread + 13

Thread 2:: Dispatch queue: com.apple.libdispatch-manager
0   libsystem_kernel.dylib          0x00007fff8eb1ad16 kevent + 10
1   libdispatch.dylib               0x00007fff96ec3dea _dispatch_mgr_invoke + 883
2   libdispatch.dylib               0x00007fff96ec39ee _dispatch_mgr_thread + 54

Thread 3:
0   libsystem_kernel.dylib          0x00007fff8eb1a6d6 __workq_kernreturn + 10
1   libsystem_c.dylib               0x00007fff93654f4c _pthread_workq_return + 25
2   libsystem_c.dylib               0x00007fff93654d13 _pthread_wqthread + 412
3   libsystem_c.dylib               0x00007fff9363f1d1 start_wqthread + 13

Thread 4:
0   libsystem_kernel.dylib          0x00007fff8eb1a6d6 __workq_kernreturn + 10
1   libsystem_c.dylib               0x00007fff93654f4c _pthread_workq_return + 25
2   libsystem_c.dylib               0x00007fff93654d13 _pthread_wqthread + 412
3   libsystem_c.dylib               0x00007fff9363f1d1 start_wqthread + 13

Thread 5:
0   libsystem_kernel.dylib          0x00007fff8eb1a6d6 __workq_kernreturn + 10
1   libsystem_c.dylib               0x00007fff93654f4c _pthread_workq_return + 25
2   libsystem_c.dylib               0x00007fff93654d13 _pthread_wqthread + 412
3   libsystem_c.dylib               0x00007fff9363f1d1 start_wqthread + 13

Thread 6:
0   libsystem_kernel.dylib          0x00007fff8eb1a6d6 __workq_kernreturn + 10
1   libsystem_c.dylib               0x00007fff93654f4c _pthread_workq_return + 25
2   libsystem_c.dylib               0x00007fff93654d13 _pthread_wqthread + 412
3   libsystem_c.dylib               0x00007fff9363f1d1 start_wqthread + 13

Thread 1 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000208  rbx: 0x00007fff7ecb5a98  rcx: 0x00000001004014c0  rdx: 0x0000000100402d30
  rdi: 0x0000000100401338  rsi: 0x00007fff7ecb5a98  rbp: 0x0000000100401250  rsp: 0x0000000100400e20
   r8: 0x00000001004014c0   r9: 0x0000000000000003  r10: 0x0000000000000000  r11: 0x00000001004012b4
  r12: 0x00000000000001ff  r13: 0x0000000100401500  r14: 0x00000001004014c0  r15: 0x0000000100402d30
  rip: 0x00007fff936c682d  rfl: 0x0000000000010202  cr2: 0x0000000100400ec8
Logical CPU: 0
2014年6月30日编辑为添加:这只是在我将Xcode升级到5.1.1(从5.0)时开始发生的。这可能是由于更改了生成设置造成的吗?(我不知道以前是什么。)我使用的是iMac(2012年底)Intel Core i5,OS 10.8.4。其中一些设置是:Base-SDK:Latest(我已经尝试限制为10.8);有效的体系结构i386、x86_64(我尝试过只使用i386或x86_64)。部署目标:10.8


7/1/14编辑添加:我使用的是NSOperationQueue(UI操作的主队列上有dispatch\u async)。删除NSOperationQueue修复了崩溃,但现在我无法更新UI(NSLog提供了一些输出)。在具有后台队列的dispatch_async()中执行我的循环也会崩溃,并且再次没有UI更新。显然,后台任务有一个与NSString相关的资源限制,我无法更改。即使我不更新我的UI,它也会崩溃(总是在创建NSString时崩溃)。

通过删除dispatch_async()并在主线程上运行它,您的问题得到了解决,这让我相信线程中的堆栈内存确实用完了。我刚刚遇到了一个类似的问题(在一组深度递归的函数中,在各种函数的顶部执行EXC_BAD_ACCESS),并且能够通过增加堆栈大小来解决这个问题。我似乎无法使用-Wl,-stack_size,。。。但也不使用NSThreads。(也许这就是为什么它对您没有帮助。)相反,我使用pthread_create()启动了该线程,首先对其调用pthread_attr_setstacksize()。此处的代码示例:

请发布完整的堆栈跟踪。很可能一些内存被覆盖,因此某些地方的内存分配将失败。检查您的源代码,特别是您写入C数组的地方。您必须显示更多的代码。@gnasher729:我没有使用任何C数组——所有内容都是NSMutableArray、NSMutableDict和NSMutableSet。