ios 如何解决 KERN_PROTECTION_FAILURE 和 KERN_INVALID_ADDRESS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6292903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:16:08  来源:igfitidea点击:

How to solve KERN_PROTECTION_FAILURE and KERN_INVALID_ADDRESS?

objective-ciosipad

提问by pkoning

How can you solve a KERN_PROTECTION_FAILURE and a KERN_INVALID ADDRESS? Both seem to happen at exactly the same spot when I run my app.

如何解决 KERN_PROTECTION_FAILURE 和 KERN_INVALID ADDRESS?当我运行我的应用程序时,两者似乎都发生在完全相同的地方。

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x6d783f44
Crashed Thread:  2

Thread 2 Crashed:
0   libobjc.A.dylib                 0x34a80464 objc_msgSend + 16
1   Foundation                      0x31171dda __+[__NSOperationInternal _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke_7 + 10
2   libSystem.B.dylib               0x30dd9678 _dispatch_call_block_and_release + 12
3   libSystem.B.dylib               0x30dd9b98 _dispatch_worker_thread2 + 120
4   libSystem.B.dylib               0x30d7e24a _pthread_wqthread + 258
5   libSystem.B.dylib               0x30d76970 start_wqthread + 0

And:

和:

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000011
Crashed Thread:  7

Thread 7 Crashed:
0   libobjc.A.dylib                 0x34a80464 objc_msgSend + 16
1   Foundation                      0x31171dfc -[NSOperation completionBlock] + 16
2   Foundation                      0x31171dda __+[__NSOperationInternal _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke_7 + 10
3   libSystem.B.dylib               0x30dd9678 _dispatch_call_block_and_release + 12
4   libSystem.B.dylib               0x30dd9b98 _dispatch_worker_thread2 + 120
5   libSystem.B.dylib               0x30d7e24a _pthread_wqthread + 258
6   libSystem.B.dylib               0x30d76970 start_wqthread + 0

Weird thing is, it crashes on an iPad 1 (iOS 4.2.1) but not on an iPad 2 (iOS 4.3.2). Could this maybe be a problem with the iPad itself or maybe with the memory? Or is it truly a bug in my code? If so, why can't I reproduce it on the iPad 2?

奇怪的是,它会在 iPad 1 (iOS 4.2.1) 上崩溃,但不会在 iPad 2 (iOS 4.3.2) 上崩溃。这可能是 iPad 本身的问题还是内存的问题?或者它真的是我代码中的错误?如果是这样,为什么我不能在 iPad 2 上重现它?

采纳答案by highlycaffeinated

EXC_BAD_ACCESSerrors are typically from trying to send a message to an object that has been deallocated. In this case, it appears to be something in your NSOperationthat has been released already. This is almost certainly a bug in your code. As for why it happens on one iPad and not the other, it could be that on one device the memory that used to contain your object has been reused but on the other it still has a zombie of your object.

EXC_BAD_ACCESS错误通常来自尝试向已解除分配的对象发送消息。在这种情况下,它似乎是你NSOperation已经发布的东西。这几乎可以肯定是您代码中的一个错误。至于为什么它发生在一个 iPad 上而不是另一个 iPad 上,可能是因为在一个设备上用于包含您的对象的内存已被重用,但在另一台设备上它仍然有您的对象的僵尸。

A much more thorough explanation is here.

更彻底的解释是here