执行选择器中的 EXC_BAD_INSTRUCTION [英] EXC_BAD_INSTRUCTION at performSelector
问题描述
我有这个代码:
dispatch_async(dispatch_get_main_queue(), ^(void){SEL 选择器 = @selector(callback:);[self.delegate performSelector:selector withObject:self];});
self.delegate
和 self
都不是 nil
.
我在 performSelector
行收到 EXC_BAD_INSTRUCTION
.
有什么想法吗?
尝试直接使用选择器,并确保callback:
是 self.delegate
的有效方法:
dispatch_async(dispatch_get_main_queue(), ^(void){[self.delegate performSelector:@selector(callback:) withObject:self];});
<小时>
另一个调试技巧是设置NSZombieEnabled, MallocStackLogging 和 在调试器中保护 malloc.然后,当您的应用程序崩溃时,在 gdb 控制台中输入:
(gdb) info malloc-history 0x543216
将 0x543216
替换为导致崩溃的对象的地址,您将获得更有用的堆栈跟踪,它应该可以帮助您查明代码中导致问题的确切行.
I have this code:
dispatch_async(dispatch_get_main_queue(), ^(void)
{
SEL selector = @selector(callback:);
[self.delegate performSelector:selector withObject:self];
});
Both self.delegate
and self
is not nil
.
I am getting EXC_BAD_INSTRUCTION
at the performSelector
line.
Any idea?
Try using the selector directly, and make surecallback:
is a valid method of self.delegate
:
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self.delegate performSelector:@selector(callback:) withObject:self];
});
Another debugging tip is to set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:
(gdb) info malloc-history 0x543216
Replace 0x543216
with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.
See this article for more detailed instructions.
这篇关于执行选择器中的 EXC_BAD_INSTRUCTION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!