执行选择器中的 EXC_BAD_INSTRUCTION [英] EXC_BAD_INSTRUCTION at performSelector

查看:19
本文介绍了执行选择器中的 EXC_BAD_INSTRUCTION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

dispatch_async(dispatch_get_main_queue(), ^(void){SEL 选择器 = @selector(callback:);[self.delegate performSelector:selector withObject:self];});

self.delegateself 都不是 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆