gpt4 book ai didi

c# - MonoMac:其他对话框出现问题

转载 作者:行者123 更新时间:2023-12-03 17:35:51 24 4
gpt4 key购买 nike

我正在 MonoMac 中编写一个应用程序,如果我使用此调用打开辅助对话框,它会遇到问题

var prefForm = new PrefFormController();
prefForm.Window.MakeKeyAndOrderFront(mainWindowController);

如果您在主对话框和辅助对话框之间来回切换足够多,那么应用程序最终会崩溃,或者单击的按钮最终会导致应用程序崩溃。

Loaded assembly: /Users/michaelmanley/Desktop/NasuTek-StreamDesk/StreamDesk-Cocoa/bin/Debug/StreamDesk.app/Contents/Resources/StreamDesk.exe
Loaded assembly: /Users/michaelmanley/Desktop/NasuTek-StreamDesk/StreamDesk-Cocoa/bin/Debug/StreamDesk.app/Contents/Resources/StreamDesk.Managed.dll
Loaded assembly: /Users/michaelmanley/Desktop/NasuTek-StreamDesk/StreamDesk-Cocoa/bin/Debug/StreamDesk.app/Contents/Resources/MonoMac.dll [External]
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/2.10.8/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll [External]
Loaded assembly: /Users/michaelmanley/Desktop/NasuTek-StreamDesk/StreamDesk-Cocoa/bin/Debug/StreamDesk.app/Contents/Resources/Mono.Addins.dll [External]
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/2.10.8/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll [External]
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/2.10.8/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll [External]
Loaded assembly: __MetadataTypes [External]
Loaded assembly: __MetadataTypes [External]
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/2.10.8/lib/mono/gac/Mono.Addins.CecilReflector/0.6.0.0__0738eb9f132ed756/Mono.Addins.CecilReflector.dll [External]
Thread started:
Unloaded assembly: /Library/Frameworks/Mono.framework/Versions/2.10.8/lib/mono/gac/Mono.Addins.CecilReflector/0.6.0.0__0738eb9f132ed756/Mono.Addins.CecilReflector.dll
Unloaded assembly: __MetadataTypes
Thread finished:
Thread started:
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/2.10.8/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll [External]
Thread started:
Thread started:
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/2.10.8/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll [External]
Thread started:
Thread started:
Loaded assembly: ObjCImplementations [External]
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/2.10.8/lib/mono/gac/System.Design/4.0.0.0__b03f5f7f11d50a3a/System.Design.dll [External]
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/2.10.8/lib/mono/gac/System.Drawing/4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll [External]
Thread finished:
Thread started:
Thread started:
Thread started:
Thread started: <---- These pop up every time you go back to the secondary window from the primary window
Thread started:

Thread started:
Thread started:
Thread started:
Stacktrace:

at (wrapper managed-to-native) MonoMac.AppKit.NSApplication.NSApplicationMain (int,string[]) <IL 0x0009d, 0xffffffff>
at MonoMac.AppKit.NSApplication.Main (string[]) [0x00000] in /cvs/monomac/src/AppKit/NSApplication.cs:74
at StreamDesk.MainClass.Main (string[]) [0x0000f] in /Users/michaelmanley/Desktop/NasuTek-StreamDesk/StreamDesk-Cocoa/StreamDesk/Main.cs:22
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

0 StreamDesk 0x00094efc mono_handle_native_sigsegv + 284
1 StreamDesk 0x00004fe8 mono_sigsegv_signal_handler + 248
2 libSystem.B.dylib 0x006db05b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 AppKit 0x04b80255 -[NSControl sendAction:to:] + 108
5 AppKit 0x04b7bd02 -[NSCell _sendActionFrom:] + 169
6 AppKit 0x04b7aff9 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 1808
7 AppKit 0x04bd06ed -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 524
8 AppKit 0x04b79a4f -[NSControl mouseDown:] + 812
9 AppKit 0x04b77a58 -[NSWindow sendEvent:] + 5549
10 AppKit 0x04a9060b -[NSApplication sendEvent:] + 6431
11 AppKit 0x04a24253 -[NSApplication run] + 917
12 AppKit 0x04a1c289 NSApplicationMain + 574
13 ??? 0x0d7d9b76 0x0 + 226335606
14 ??? 0x0d7d9974 0x0 + 226335092
15 ??? 0x00dee048 0x0 + 14606408
16 ??? 0x00dee1be 0x0 + 14606782
17 StreamDesk 0x0000d282 mono_jit_runtime_invoke + 722
18 StreamDesk 0x001a436a mono_runtime_invoke + 170
19 StreamDesk 0x001a6f01 mono_runtime_exec_main + 705
20 StreamDesk 0x001a6111 mono_runtime_run_main + 929
21 StreamDesk 0x00069995 mono_jit_exec + 149
22 StreamDesk 0x0006bf13 mono_main + 9587
23 StreamDesk 0x00002299 main + 441
24 StreamDesk 0x000020a6 start + 54
25 ??? 0x00000001 0x0 + 1

异常可能有所不同,这使得调试此问题变得困难,我知道可以重现它的唯一方法是从主窗口来回,然后返回到辅助窗口,一段时间后,应用程序将终止

我显示对话框的方式是否错误,或者这是 Mono 本身的错误,但我不知道 Mono 可能存在如此规模的巨大错误,您甚至无法显示其他窗口。

最佳答案

问题是托管对象在其相应的 native 对象之前被释放。然后 native 对象尝试调用托管对象上的方法,应用程序崩溃。

您可以通过每秒运行一次 GC 来使其更具可重复性:

ThreadPool.QueueUserWorkItem ((v) =>
{
while (true) {
Thread.Sleep (1000);
GC.Collect (GC.MaxGenerations);
}
});

这就是问题所在:

3   ???        0xffffffff 0x0 + 4294967295
4 AppKit 0x04b80255 -[NSControl sendAction:to:] + 108

看起来问题出在 NSControl(或派生)实例上。除此之外,很难说哪个对象实际上被可用信息释放了。解决这个问题的最简单方法可能是人为地保持对象处于事件状态(例如将它们添加到静态列表中),然后减少保持事件的对象子集,直到查明导致崩溃的确切实例。

一旦您发现哪个对象被过早释放,您就必须确保 GC 不会过早释放它(一种方法是将其添加到静态列表中,但最好的方法取决于每种情况)。

请记住,该对象不必是您在代码中显式创建的对象,它也可以是委托(delegate)或事件处理程序等。

关于c# - MonoMac:其他对话框出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9182902/

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