gpt4 book ai didi

cocoa - NSWorkspace setIcon :forFile:options: crashes

转载 作者:行者123 更新时间:2023-12-03 17:23:19 30 4
gpt4 key购买 nike

我有时会在 [NSWorkspace setIcon:forFile:options:] API 上遇到崩溃。

感谢任何帮助。这是崩溃堆栈,

0   libsystem_kernel.dylib          0x00007fff85bfbe56 __semwait_signal_nocancel + 10
1 libsystem_c.dylib 0x00007fff8c04818b nanosleep$NOCANCEL + 139
2 libsystem_c.dylib 0x00007fff8bfe7c78 usleep$NOCANCEL + 53
3 libsystem_c.dylib 0x00007fff8bfe7aa6 abort + 187
4 libsystem_c.dylib 0x00007fff8c04684c free + 389
5 com.apple.CoreServices.CarbonCore 0x00007fff8df7aaf7 CSMemDisposePtr + 23
6 com.apple.CoreServices.CarbonCore 0x00007fff8df7aaba CSMemDisposeHandle + 79
7 com.apple.CoreServices.CarbonCore 0x00007fff8df7c355 DisposeHandle + 9
8 com.apple.AppKit 0x00007fff90356598 -[NSWorkspace setIcon:forFile:options:] + 566

这是代码,

static NSImage  *FolderIcon = nil;

if(!FolderIcon) {
FolderIcon = [[NSImage imageNamed:@"xxx.icns"] retain];
}

if(![[NSWorkspace sharedWorkspace] setIcon: FolderIcon
forFile:Path
options:0]) {
NSLog(@"error");
}

我使用的是静态图标,所以我不认为悬空指针的可能性,我还检查了如果我们传递不存在的文件路径,那么它返回“NO”。但它并没有崩溃。

这很少能重现。一旦重现就会粘贴错误

最佳答案

您不应一次从多个线程调用 -setIcon:forFile:options:

来自Documentation :

It is safe to call this method from any of your app’s threads, but you must call it from only one thread at a time.

关于cocoa - NSWorkspace setIcon :forFile:options: crashes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14570758/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com