diff --git a/Source/Examples/ExampleBrowser.cs b/Source/Examples/ExampleBrowser.cs index 5e618a76..5c81e4f9 100644 --- a/Source/Examples/ExampleBrowser.cs +++ b/Source/Examples/ExampleBrowser.cs @@ -425,7 +425,10 @@ namespace Examples Trace.Listeners.Add(dbg); Trace.Listeners.Add(new ConsoleTraceListener()); - _main.Invoke(null, null); + using (OpenTK.Toolkit.Init()) + { + _main.Invoke(null, null); + } dbg.Flush(); dbg.Close(); diff --git a/Source/Examples/Main.cs b/Source/Examples/Main.cs index 71d84d8c..0ab8b7b1 100644 --- a/Source/Examples/Main.cs +++ b/Source/Examples/Main.cs @@ -37,14 +37,26 @@ namespace Examples { static class Program { + static void EnableOpenTKHack() + { + // If OpenTK is not initialized before Windows.Forms, + // the program will crash on Mac OS X. This hack will + // enable OpenTK in a temporary AppDomain before entering + // the main program - this appears to be enough. + var domain = AppDomain.CreateDomain("sandbox"); + domain.DoCallBack(() => { + using (OpenTK.Toolkit.Init()) + { + } + }); + } + [STAThread] public static void Main() { try { - // This seems to be useful enough to leave in for a while. - TextWriterTraceListener console = new TextWriterTraceListener(System.Console.Out); - Trace.Listeners.Add (console); + EnableOpenTKHack(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);