gpt4 book ai didi

objective-c - 自 OSX 10.8 起屏幕保护程序崩溃

转载 作者:行者123 更新时间:2023-12-03 17:04:57 25 4
gpt4 key购买 nike

自 OSX 10.8 起,我的屏幕保护程序发生崩溃:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff94749790 objc_msgSend_vtable13 + 16
1 com.apple.Foundation 0x00007fff9508941f -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] + 163
2 com.apple.Foundation 0x00007fff950892f8 -[NSObject(NSThreadPerformAdditions) performSelectorOnMainThread:withObject:waitUntilDone:] + 131
3 albertzeyer.PictureSlider 0x000000010f6e64c7 -[PictureSliderView nextFileName] + 71 (PictureSliderView.m:69)
4 albertzeyer.PictureSlider 0x000000010f6e6675 -[PictureSliderView loadNext] + 53 (PictureSliderView.m:86)
5 albertzeyer.PictureSlider 0x000000010f6e695f -[PictureSliderView initWithFrame:isPreview:] + 447 (PictureSliderView.m:116)
6 com.apple.ScreenSaver 0x00007fff968c7cb5 -[ScreenSaverModules loadModule:frame:isPreview:] + 968

相关代码:

- (void) queuedFileNamesPop:(NSString**)fn {
if([queuedFileNames count] > 0) {
*fn = [queuedFileNames objectAtIndex:0];
[queuedFileNames removeObjectAtIndex:0];
}
}

- (NSString*) nextFileName
{
NSString* fn = nil;
[self performSelectorOnMainThread:@selector(queuedFileNamesPop:) withObject:(id)&fn waitUntilDone:YES];
if(!fn) {
[nextFileNameLock lock];
fn = [[NSString alloc] initWithUTF8String:FileQueue_getNextFile()];
[nextFileNameLock unlock];
}
return fn;
}

它似乎在 performSelectorOnMainThread 上崩溃,但我真的不明白为什么。我做错了什么明显的事情吗?

此外,只有从 ScreenSaverEngine 运行时才会崩溃。我还有一个小型虚拟应用程序,它使用相同的 View 来测试屏幕保护程序,并且它不会在那里崩溃。

<小时/>

编辑:不久前我问过一些非常相关的事情(相同的代码)here 。我想知道为什么我最终没有采取这些解决方案之一......

<小时/>

编辑:在乔纳森建议的代码更改之后,此崩溃不再发生。然而,在其他事件中,我遇到了其他崩溃,并带有以下回溯:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.apple.CoreFoundation 0x00007fff8f9aefe8 CFRelease + 248
1 com.apple.CoreFoundation 0x00007fff8f9d6770 -[__NSArrayM removeObjectAtIndex:] + 400
2 albertzeyer.PictureSlider 0x0000000108c54425 -[PictureSliderView queuedFileNamesPop:] + 197 (PictureSliderView.m:64)
3 com.apple.Foundation 0x00007fff95089450 -[NSObject(NSThreadPerformAdditions) performSelector:onThread:withObject:waitUntilDone:modes:] + 212
4 com.apple.Foundation 0x00007fff950892f8 -[NSObject(NSThreadPerformAdditions) performSelectorOnMainThread:withObject:waitUntilDone:] + 131
5   albertzeyer.PictureSlider     0x0000000108c544b0 -[PictureSliderView nextFileName] + 128 (PictureSliderView.m:71)
6   albertzeyer.PictureSlider     0x0000000108c54665 -[PictureSliderView loadNext] + 53 (PictureSliderView.m:88)
7   albertzeyer.PictureSlider     0x0000000108c54cce -[PictureSliderView keyDown:] + 382 (PictureSliderView.m:178)
8   com.apple.AppKit               0x00007fff924ad8e0 -[NSWindow sendEvent:] + 9687

或者这个:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff947497d0 objc_msgSend_vtable14 + 16
1 com.apple.CoreFoundation 0x00007fff8f9aef9a CFRelease + 170
2 com.apple.CoreFoundation 0x00007fff8f9d6770 -[__NSArrayM removeObjectAtIndex:] + 400
3 albertzeyer.PictureSlider 0x00000001023fac51 -[PictureSliderView keyDown:] + 257 (PictureSliderView.m:172)
4 com.apple.AppKit 0x00007fff924ad8e0 -[NSWindow sendEvent:] + 9687

我还不确定它们是相关的还是独立的。

编辑:他们没有关系。它们是因为其他地方的另一个额外的[fn release]

最佳答案

您正在将非对象转换为对象。这可能与 Objective-C 运行时或 Foundation 中的内存管理更改相冲突(看起来他们可能已经开始构建启用了 ARC 的 NSObject 。)

不要使用(id)&fn,试试这个:

NSValue *fnHandle = [NSValue valueWithPointer: &fn];
[self performSelectorOnMainThread: @selector(queuedFileNamesPop:) withObject: fnHandle waitUntilDone: YES];

这传递了包装在对象中的fn的地址。然后,在被调用的方法中:

- (void)queuedFileNamesPop: (NSValue *)fnHandle {
NSString **fn = [fnHandle pointerValue];
if (fn) {
// existing code here
}
}

这可确保始终遵循正确的内存管理。

关于objective-c - 自 OSX 10.8 起屏幕保护程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11669298/

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