简体   繁体   English

GCD块在调用时触发EXC_BAD_ACCESS

[英]GCD block triggering EXC_BAD_ACCESS on invoke

I'm making a non-garbage-collected MacFUSE Cocoa application, inside of which I want to use a GCD block as a delegate. 我正在制作一个非垃圾收集的MacFUSE Cocoa应用程序,在其中要使用GCD块作为委托。 However, my program crashes during the invocation of the block, leaving only an EXC_BAD_ACCESS in its trail. 但是,我的程序在调用该块的过程中崩溃,仅在其跟踪中留下了EXC_BAD_ACCESS

My program uses a framework built agains the Mac OS 10.5 SDK that does not support garbage collection (nor 64 bits) and the MacFUSE framework. 我的程序使用的是不支持垃圾回收(也不支持64位)的Mac OS 10.5 SDK和MacFUSE框架。 The program builds with no warning or error as a 32-bit program. 该程序构建时没有警告或错误作为32位程序。 Other build settings (such as optimization level) were left to their original values. 其他构建设置(例如优化级别)保留其原始值。

So I have my application controller, from which I create this block and call runWithContinuation: 因此,我有了我的应用程序控制器,从中创建此块并调用runWithContinuation:

AFSPasswordPrompt* prompt = [[AFSPasswordPrompt alloc] initWithIcon:icon];
dispatch_block_t continuation = ^{
    archive.password = prompt.password;
    [self mountFilesystem:fsController];
    [prompt performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
};
[prompt runWithContinuation:continuation];

runWithContinuation: retains the block and instantiates a nib. runWithContinuation:保留块并实例化一个nib。 The block is called only once the user dismisses the password prompt by pressing the "Open" button. 仅当用户通过按“打开”按钮消除密码提示后,该块才被调用。

-(void)runWithContinuation:(dispatch_block_t)block
{
    continuation = [block retain];
    [passwordPrompt instantiateNibWithOwner:self topLevelObjects:NULL];
    imageView.image = image;
    [window makeKeyWindow];
}

-(IBAction)open:(id)sender
{
    continuation();
    [self close];
}

-(void)close
{
    [window close];
    [continuation release];
}

My problem is that when I hit continuation() , my program triggers an EXC_BAD_ACCESS , and the last stack frame is called ?? 我的问题是,当我点击continuation() ,程序会触发EXC_BAD_ACCESS ,最后一个堆栈帧称为?? . Right under it is the open: method call. 正下方是open:方法调用。

I really don't know where it's coming from. 我真的不知道它来自哪里。 NSZombies are enabled, and they don't report anything. NSZombies已启用,并且不报告任何内容。

Any ideas? 有任何想法吗?

try copying the block instead of retaining it. 尝试复制该块而不是保留它。 A block lives on the stack until you call copy, then it is copied to the heap. 块一直存在于堆栈中,直到您调用copy为止,然后将其复制到堆中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM