出现奇怪的间歇性“无法识别的选择器” iPhone 应用程序中的异常

发布于 2024-09-24 02:22:37 字数 5406 浏览 9 评论 0原文

最近,我从我的应用程序中收到间歇性错误报告,声称在不可能导致这些错误的区域出现“无法识别的选择器”,但它们确实如此。

例如,这个:

Error: NSInvalidArgumentException: *** -[NSCFString didReceiveMemoryWarning]: unrecognized selector sent to instance 0x541fe0
0  CoreFoundation                      0x32de1e23 __handleUncaughtException + 230
1  libobjc.A.dylib                    0x3266d894 _objc_terminate + 156
2  libstdc++.6.dylib                  0x338c3a8c _ZN10__cxxabiv111__terminateEPFvvE + 84
3  libstdc++.6.dylib                  0x338c3b04 _ZSt9terminatev + 24
4  libstdc++.6.dylib                  0x338c3c2c __cxa_throw + 108
5  libobjc.A.dylib                    0x3266be5c objc_exception_throw + 112
6  CoreFoundation                      0x32de2bfd -[NSObject doesNotRecognizeSelector:] + 112
7  CoreFoundation                      0x32d67b19 ___forwarding___ + 480
8  CoreFoundation                      0x32d5e840 _CF_forwarding_prep_0 + 48
9  Foundation                          0x33f765d9 _nsnote_callback + 184
10  CoreFoundation                      0x32d9e511 _CFXNotificationPostNotification + 304
11  Foundation                          0x33f741b3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
12  Foundation                          0x33f76519 -[NSNotificationCenter postNotificationName:object:] + 20
13  UIKit                              0x30d18db8 -[UIApplication _performMemoryWarning] + 68
14  UIKit                              0x30d18d50 -[UIApplication _receivedMemoryNotification] + 136
15  UIKit                              0x30d18c80 _memoryStatusChanged + 64
16  CoreFoundation                      0x32d66eb7 __CFNotificationCenterDarwinCallBack + 26
17  CoreFoundation                      0x32d5cb51 __CFMachPortPerform + 78
18  CoreFoundation                      0x32da452b CFRunLoopRunSpecific + 2302
19  CoreFoundation                      0x32da3c1f CFRunLoopRunInMode + 50
20  GraphicsServices                    0x31bb9374 GSEventRunModal + 196
21  UIKit                              0x30bf3c30 -[UIApplication _run] + 560
22  UIKit                              0x30bf2230 UIApplicationMain + 968
23  Mind                                0x00002c68 main + 72
24  Mind                                0x00002be4 start + 52

这是操作系统向我的应用程序发送内存警告,并且不知何故应用程序类已更改为字符串。

当通过 NSOperation 调用代码时,似乎会发生更多的情况:

Error: NSInvalidArgumentException: -[NSCFString setObject:forKey:]: unrecognized selector sent to instance 0x3e793088
9  Mind                                0x0015de70 -[CCTextureCache textureFromFile:] + 528
10  Mind                                0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11  Mind                                0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12  Mind                                0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13  Mind                                0x000854c4 -[ImageLoadOperation performLoad] + 68
14  Mind                                0x00085800 -[ResourceLoadOperation main] + 112
15  Foundation                          0x30c4c8b5 -[__NSOperationInternal start] + 664
16  Foundation                          0x30c4c613 -[NSOperation start] + 22
17  Foundation                          0x30cbdb63 ____startOperations_block_invoke_2 + 46
18  libSystem.B.dylib                  0x31227858 _dispatch_call_block_and_release + 20
19  libSystem.B.dylib                  0x3122863c _dispatch_worker_thread2 + 128
20  libSystem.B.dylib                  0x311b1544 _pthread_wqthread + 400
21  libSystem.B.dylib                  0x311a8b74 __stack_chk_fail + 4294967295

有问题的代码是:

[textures setObject:texture forKey:filename];

纹理是 NSMutableDictionary* 类型,并且永远不会被重新分配或释放(当然,因为这是一个缓存对象)。这是该方法中唯一调用 setObject 的地方,但根据堆栈跟踪,纹理是一个字符串。

我也得到了这个奇怪的地方:

Error: NSInvalidArgumentException: -[NSConcreteNotification getPixelFormatForIdentifier:]: unrecognized selector sent to instance 0x5c021b0
9  Mind                                0x0015dd0c -[CCTextureCache textureFromFile:] + 172
10  Mind                                0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11  Mind                                0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12  Mind                                0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13  Mind                                0x000854c4 -[ImageLoadOperation performLoad] + 68
14  Mind                                0x00085800 -[ResourceLoadOperation main] + 112
15  Foundation                          0x347b78b5 -[__NSOperationInternal start] + 664
16  Foundation                          0x347b7613 -[NSOperation start] + 22
17  Foundation                          0x34828b63 ____startOperations_block_invoke_2 + 46
18  libSystem.B.dylib                  0x32a2f858 _dispatch_call_block_and_release + 20
19  libSystem.B.dylib                  0x32a3063c _dispatch_worker_thread2 + 128
20  libSystem.B.dylib                  0x329b9544 _pthread_wqthread + 400
21  libSystem.B.dylib                  0x329b0b74 __stack_chk_fail + 4294967295

此跟踪来自 CCTextureCache 中的以下代码:

CCTexture2DPixelFormat PixelFormat = [self getPixelFormatForIdentifier:identifier];

至少可以说,在调用了许多方法之后,CCTextureCache 如何变成 NSConcreteNotification 是令人费解的。

还有其他人注意到这种事情吗?我是否以某种方式出现内存损坏?

Recently, I've been getting intermittent error reports from my app claiming "unrecognized selector" in areas that could not possibly cause them, and yet they do.

For example, this one:

Error: NSInvalidArgumentException: *** -[NSCFString didReceiveMemoryWarning]: unrecognized selector sent to instance 0x541fe0
0  CoreFoundation                      0x32de1e23 __handleUncaughtException + 230
1  libobjc.A.dylib                    0x3266d894 _objc_terminate + 156
2  libstdc++.6.dylib                  0x338c3a8c _ZN10__cxxabiv111__terminateEPFvvE + 84
3  libstdc++.6.dylib                  0x338c3b04 _ZSt9terminatev + 24
4  libstdc++.6.dylib                  0x338c3c2c __cxa_throw + 108
5  libobjc.A.dylib                    0x3266be5c objc_exception_throw + 112
6  CoreFoundation                      0x32de2bfd -[NSObject doesNotRecognizeSelector:] + 112
7  CoreFoundation                      0x32d67b19 ___forwarding___ + 480
8  CoreFoundation                      0x32d5e840 _CF_forwarding_prep_0 + 48
9  Foundation                          0x33f765d9 _nsnote_callback + 184
10  CoreFoundation                      0x32d9e511 _CFXNotificationPostNotification + 304
11  Foundation                          0x33f741b3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
12  Foundation                          0x33f76519 -[NSNotificationCenter postNotificationName:object:] + 20
13  UIKit                              0x30d18db8 -[UIApplication _performMemoryWarning] + 68
14  UIKit                              0x30d18d50 -[UIApplication _receivedMemoryNotification] + 136
15  UIKit                              0x30d18c80 _memoryStatusChanged + 64
16  CoreFoundation                      0x32d66eb7 __CFNotificationCenterDarwinCallBack + 26
17  CoreFoundation                      0x32d5cb51 __CFMachPortPerform + 78
18  CoreFoundation                      0x32da452b CFRunLoopRunSpecific + 2302
19  CoreFoundation                      0x32da3c1f CFRunLoopRunInMode + 50
20  GraphicsServices                    0x31bb9374 GSEventRunModal + 196
21  UIKit                              0x30bf3c30 -[UIApplication _run] + 560
22  UIKit                              0x30bf2230 UIApplicationMain + 968
23  Mind                                0x00002c68 main + 72
24  Mind                                0x00002be4 start + 52

This is the OS sending a memory warning to my app, and somehow the application class has changed into a string.

It seems to happen a lot more when the code is invoked via an NSOperation:

Error: NSInvalidArgumentException: -[NSCFString setObject:forKey:]: unrecognized selector sent to instance 0x3e793088
9  Mind                                0x0015de70 -[CCTextureCache textureFromFile:] + 528
10  Mind                                0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11  Mind                                0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12  Mind                                0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13  Mind                                0x000854c4 -[ImageLoadOperation performLoad] + 68
14  Mind                                0x00085800 -[ResourceLoadOperation main] + 112
15  Foundation                          0x30c4c8b5 -[__NSOperationInternal start] + 664
16  Foundation                          0x30c4c613 -[NSOperation start] + 22
17  Foundation                          0x30cbdb63 ____startOperations_block_invoke_2 + 46
18  libSystem.B.dylib                  0x31227858 _dispatch_call_block_and_release + 20
19  libSystem.B.dylib                  0x3122863c _dispatch_worker_thread2 + 128
20  libSystem.B.dylib                  0x311b1544 _pthread_wqthread + 400
21  libSystem.B.dylib                  0x311a8b74 __stack_chk_fail + 4294967295

The code in question is:

[textures setObject:texture forKey:filename];

textures is type NSMutableDictionary* and never gets reassigned or deallocated (naturally, since this is a cache object). This is the only place where setObject is invoked in this method, yet according to the stack trace, textures was a string.

I also get this weirdness:

Error: NSInvalidArgumentException: -[NSConcreteNotification getPixelFormatForIdentifier:]: unrecognized selector sent to instance 0x5c021b0
9  Mind                                0x0015dd0c -[CCTextureCache textureFromFile:] + 172
10  Mind                                0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11  Mind                                0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12  Mind                                0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13  Mind                                0x000854c4 -[ImageLoadOperation performLoad] + 68
14  Mind                                0x00085800 -[ResourceLoadOperation main] + 112
15  Foundation                          0x347b78b5 -[__NSOperationInternal start] + 664
16  Foundation                          0x347b7613 -[NSOperation start] + 22
17  Foundation                          0x34828b63 ____startOperations_block_invoke_2 + 46
18  libSystem.B.dylib                  0x32a2f858 _dispatch_call_block_and_release + 20
19  libSystem.B.dylib                  0x32a3063c _dispatch_worker_thread2 + 128
20  libSystem.B.dylib                  0x329b9544 _pthread_wqthread + 400
21  libSystem.B.dylib                  0x329b0b74 __stack_chk_fail + 4294967295

This trace is from the following code in CCTextureCache:

CCTexture2DPixelFormat pixelFormat = [self getPixelFormatForIdentifier:identifier];

How CCTextureCache changed into NSConcreteNotification after having already called a number of methods on itself is baffling to say the least.

Has anyone else noticed this sort of thing? Am I somehow getting memory corruption?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倦话 2024-10-01 02:22:37

您检查过有关多线程的一些竞争条件吗?似乎某些资源被另一个线程释放,并且当前线程向已释放的对象发送消息。

Error: NSInvalidArgumentException: -[NSCFString setObject:forKey:]: unrecognized selector sent to instance 0x3e793088
9  Mind                                0x0015de70 -[CCTextureCache textureFromFile:] + 528
10  Mind                                0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11  Mind                                0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12  Mind                                0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13  Mind                                0x000854c4 -[ImageLoadOperation performLoad] + 68
14  Mind                                0x00085800 -[ResourceLoadOperation main] + 112
15  Foundation                          0x30c4c8b5 -[__NSOperationInternal start] + 664
16  Foundation                          0x30c4c613 -[NSOperation start] + 22
17  Foundation                          0x30cbdb63 ____startOperations_block_invoke_2 + 46
18  libSystem.B.dylib                  0x31227858 _dispatch_call_block_and_release + 20
19  libSystem.B.dylib                  0x3122863c _dispatch_worker_thread2 + 128
20  libSystem.B.dylib                  0x311b1544 _pthread_wqthread + 400
21  libSystem.B.dylib                  0x311a8b74 __stack_chk_fail + 4294967295

Did you check some race conditions about multi-threads ? It seems like some resource freed by another thread, and current thread send a messaged to a deallocated object.

Error: NSInvalidArgumentException: -[NSCFString setObject:forKey:]: unrecognized selector sent to instance 0x3e793088
9  Mind                                0x0015de70 -[CCTextureCache textureFromFile:] + 528
10  Mind                                0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11  Mind                                0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12  Mind                                0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13  Mind                                0x000854c4 -[ImageLoadOperation performLoad] + 68
14  Mind                                0x00085800 -[ResourceLoadOperation main] + 112
15  Foundation                          0x30c4c8b5 -[__NSOperationInternal start] + 664
16  Foundation                          0x30c4c613 -[NSOperation start] + 22
17  Foundation                          0x30cbdb63 ____startOperations_block_invoke_2 + 46
18  libSystem.B.dylib                  0x31227858 _dispatch_call_block_and_release + 20
19  libSystem.B.dylib                  0x3122863c _dispatch_worker_thread2 + 128
20  libSystem.B.dylib                  0x311b1544 _pthread_wqthread + 400
21  libSystem.B.dylib                  0x311a8b74 __stack_chk_fail + 4294967295
小忆控 2024-10-01 02:22:37

这通常是由内存管理错误引起的。你尝试过僵尸吗?

...启用僵尸后,发送给已释放对象的消息将不再起作用
奇怪地或以难以理解的方式崩溃,但会记录一条消息
并以可预测且可调试器断点的方式死亡。这是要使用的工具
当试图追踪过度发布和过早发布时。

This is often caused by memory management errors. Did you try zombies?

...with zombies enabled, messages to deallocated objects will no longer behave
strangely or crash in difficult-to-understand ways, but will instead log a message
and die in a predictable and debugger-breakpointable way. This is the tool to use
when trying to track down over-releases and premature releases.

淡莣 2024-10-01 02:22:37

我刚刚遇到了同样的问题,但事实证明我犯了一个愚蠢的错误:

我在头文件中声明了一个这样的成员:

NSMutableDictionary* myDict; 

但是然后在 .m 文件中像这样初始化了它:

myDict = [[NSDictionary alloc] init];

这是有效的,因为NSMutableDictionary 派生自 NSDictionary 类。因此,从 NSDictionary 继承的所有调用实际上都有效,但特定于 NSMutableDictionary [setObject: forKey:] 的调用失败了,因为我试图在父类上调用它们。

这个错误确实很愚蠢,但调试器将 myDict 的类型报告为完全不同的类型(既不是 NSDictionary,也不是 NSMutableDictionary),这一事实也让我感到困惑。我希望这可以帮助其他一些疲惫的编码员:-)

I just ran into the same problem, but it turns out I had made a stupid mistake:

I had declared a member like this in the header file:

NSMutableDictionary* myDict; 

But then initialized it like this in the .m file:

myDict = [[NSDictionary alloc] init];

which is valid and all, because the NSMutableDictionary is derived from the NSDictionary class. Therefore all calls that are inherited from NSDictionary actually worked, but the calls specific to NSMutableDictionary [setObject: forKey:] failed because I tried to invoke them on the parent class.

The mistake was really dumb, but I was also thrown off by the fact that the debugger reported the type of myDict as something totally different (neither NSDictionary, nor NSMutableDictionary). I hope this helps some other tired coder :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文