diff options
author | Alex Corrado <alexc@xamarin.com> | 2016-09-01 19:09:21 +0300 |
---|---|---|
committer | Alex Corrado <alexc@xamarin.com> | 2016-09-01 19:16:23 +0300 |
commit | 2670780396856f043ab5cea9ab856641f56de5ae (patch) | |
tree | e6a0cee6564f79dec49c4d126e190e9235a5e751 | |
parent | 0eaf2cc41fb52b6f5a4a609148f884f185518d98 (diff) |
[Mac] Try to dlopen libxammac.dylib before initializing X.Mac
Works around https://bugzilla.xamarin.com/show_bug.cgi?id=43932
-rw-r--r-- | src/framework/GuiUnit/MonoMacMainLoopIntegration.cs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/framework/GuiUnit/MonoMacMainLoopIntegration.cs b/src/framework/GuiUnit/MonoMacMainLoopIntegration.cs index 8451cca..6774694 100644 --- a/src/framework/GuiUnit/MonoMacMainLoopIntegration.cs +++ b/src/framework/GuiUnit/MonoMacMainLoopIntegration.cs @@ -1,5 +1,7 @@ using System; +using System.IO; using System.Linq; +using System.Runtime.InteropServices; namespace GuiUnit { @@ -25,6 +27,14 @@ namespace GuiUnit public void InitializeToolkit () { + // First, dlopen libxammac.dylib from the same dir we loaded the Xamarin.Mac dll + var dylibPath = Path.Combine (Path.GetDirectoryName (Application.Assembly.Location), "libxammac.dylib"); + if (dlopen (dylibPath, 0) == IntPtr.Zero) { + var errPtr = dlerror (); + var errStr = (errPtr == IntPtr.Zero)? "<unknown error>" : Marshal.PtrToStringAnsi (errPtr); + Console.WriteLine ("WARNING: Cannot load {0}: {1}", dylibPath, errStr); + } + var initMethod = Application.GetMethod ("Init", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); initMethod.Invoke (null, null); @@ -49,6 +59,12 @@ namespace GuiUnit { Application.GetMethod ("Terminate").Invoke (SharedApplication, new [] { SharedApplication }); } + + [DllImport ("/usr/lib/libSystem.dylib")] + static extern IntPtr dlopen (string path, int mode); + + [DllImport ("/usr/lib/libSystem.dylib")] + static extern IntPtr dlerror (); } } |