gpt4 book ai didi

ios - 分配 NSMutableArray 时的 EXC_BAD_ACCESS

转载 作者:行者123 更新时间:2023-11-29 12:29:44 26 4
gpt4 key购买 nike

这有点奇怪。

在我的代码中,我有这一行:

    NSMutableArray *unresolvedPlayers = [NSMutableArray arrayWithCapacity:3];

这似乎是一条完全有效的线路。我在这 strip 有堆栈跟踪的行上崩溃了(我已经用 xxxxxxxxx 替换了我的应用程序名称):

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

Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 libsystem_kernel.dylib 0x3870d648 syscall_thread_switch + 8
1 libsystem_platform.dylib 0x3879a79a _os_lock_handoff_lock_slow + 74
2 libsystem_malloc.dylib 0x38748ece szone_malloc_should_clear + 50
3 libsystem_malloc.dylib 0x3874c444 malloc_zone_calloc + 92
4 libsystem_malloc.dylib 0x3874c3d2 calloc + 46
5 libobjc.A.dylib 0x380c8414 class_createInstance + 36
6 CoreFoundation 0x2a5773d0 __CFAllocateObject2 + 8
7 CoreFoundation 0x2a48c86a +[__NSArrayM __new:::::] + 38
8 CoreFoundation 0x2a48fd7c -[__NSPlaceholderArray initWithCapacity:] + 100
9 CoreFoundation 0x2a497e88 +[NSMutableArray arrayWithCapacity:] + 36
10 xxxxxxxxxx 0x001730f4 -[HostManager setHost:timestamp:] (HostManager.m:703)
11 xxxxxxxxxx 0x0016ff10 -[HostManager initSessionFromInvitation:] (HostManager.m:46)
12 xxxxxxxxxx 0x000ea68e -[NetworkController updateWithMatch:] (NetworkController.m:894)
13 xxxxxxxxxx 0x000ea418 __72-[NetworkController invitePlayersToMatch:playerGroup:completionHandler:]_block_invoke544 (NetworkController.m:844)
14 GameCenterFoundation 0x31263936 __72-[GKMatchmaker invitePlayersWithRequest:serverHosted:completionHandler:]_block_invoke601 + 42
15 libdispatch.dylib 0x38620420 _dispatch_call_block_and_release + 8
16 libdispatch.dylib 0x3862040c _dispatch_client_callout + 20
17 libdispatch.dylib 0x3862b1b0 _dispatch_main_queue_callback_4CF$VARIANT$mp + 708
18 CoreFoundation 0x2a53762c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 4
19 CoreFoundation 0x2a535d4c __CFRunLoopRun + 1508
20 CoreFoundation 0x2a482b2c CFRunLoopRunSpecific + 472
21 CoreFoundation 0x2a48293e CFRunLoopRunInMode + 102
22 GraphicsServices 0x3183904c GSEventRunModal + 132
23 UIKit 0x2da786ec UIApplicationMain + 1436
24 xxxxxxxxxx 0x000503b2 main (main.m:16)
25 libdyld.dylib 0x3865baac start + 0

到目前为止,我的内存怎么可能已经损坏,以至于分配一个新的 NSMutableArray 会导致这种情况发生?我什至不确定从哪里开始调试这个。我不确定这是否容易重现。

作为旁注,它发生在邀请附近的玩家参加实时 GameCenter 比赛时。

编辑:我刚刚意识到这在线程 7 上崩溃了。这就是线程 7 的样子:

Thread 7 name:  Dispatch queue: com.apple.root.default-qos
Thread 7 Crashed:
0 libobjc.A.dylib 0x380cbf66 objc_msgSend + 6
1 GameCenterFoundation 0x31285efc -[GKMatchmaker(Nearby) inviteAnyNearbyPlayersWithRequest:] + 960
2 GameCenterFoundation 0x312636a8 __72-[GKMatchmaker invitePlayersWithRequest:serverHosted:completionHandler:]_block_invoke + 256
3 GameCenterFoundation 0x3129ae92 __39-[GKDispatchGroup notifyOnQueue:block:]_block_invoke44 + 10
4 libdispatch.dylib 0x38620420 _dispatch_call_block_and_release + 8
5 libdispatch.dylib 0x3862c2d6 _dispatch_root_queue_drain + 846
6 libdispatch.dylib 0x3862d1f6 _dispatch_worker_thread3 + 102
7 libsystem_pthread.dylib 0x3879de22 _pthread_wqthread + 666
8 libsystem_pthread.dylib 0x3879db74 start_wqthread + 4

所以,这可能是 GameCenter 的一个错误。

最佳答案

objc_msgSend 中的崩溃可能表明消息目标对象已被释放。试试enable zombie objects并关注日志。

关于ios - 分配 NSMutableArray 时的 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28083946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com