MonoMac:与其他对话有问题

时间:2012-02-07 19:54:10

标签: c# cocoa mono monomac

我正在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可能会出现这种规模的大错误,甚至无法显示其他窗口。

1 个答案:

答案 0 :(得分:3)

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

通过每秒运行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不会过早释放它(一种方法是将它添加到静态列表中,但最好的方法取决于每种情况)。

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