GCD 块在调用时触发 EXC_BAD_ACCESS

发布于 2024-10-03 06:05:20 字数 1313 浏览 5 评论 0原文

我正在制作一个非垃圾收集的 MacFUSE Cocoa 应用程序,在其中我想使用 GCD 块作为委托。但是,我的程序在调用该块期间崩溃,只留下 EXC_BAD_ACCESS

我的程序使用基于 Mac OS 10.5 SDK 构建的框架,该框架不支持垃圾收集(也不支持 64 位)和 MacFUSE 框架。该程序作为 32 位程序构建时没有任何警告或错误。其他构建设置(例如优化级别)保留为原始值。

所以我有我的应用程序控制器,我从中创建这个块并调用 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: 保留该块并实例化一个笔尖。仅当用户通过按“打开”按钮取消密码提示时才会调用该块。

-(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];
}

我的问题是,当我点击 continuation() 时,我的程序会触发 EXC_BAD_ACCESS,最后一个堆栈帧被称为 ??。其正下方是 open: 方法调用。

我真的不知道它是从哪里来的。 NSZombies 已启用,并且它们不报告任何内容。

有什么想法吗?

I'm making a non-garbage-collected MacFUSE Cocoa application, inside of which I want to use a GCD block as a delegate. However, my program crashes during the invocation of the block, leaving only an EXC_BAD_ACCESS in its trail.

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. The program builds with no warning or error as a 32-bit program. 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:

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. 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 ??. Right under it is the open: method call.

I really don't know where it's coming from. NSZombies are enabled, and they don't report anything.

Any ideas?

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

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

发布评论

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

评论(1

栩栩如生 2024-10-10 06:05:20

尝试复制该块而不是保留它。块一直存在于堆栈中,直到您调用 copy,然后它才会被复制到堆中。

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.

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