I am on OSX and trying to create a simple window from my game, but, when I do, I get a “DLLNotFoundException: glibsharpglue-2” error. Right now I’ve just got the GTK DLLs copied over to my project (atk-sharp, gdk-sharp, glade-sharp, glib-sharp, gtk-sharp, and pango-sharp) that I copied from the MonoDevelop install that came with Unity.
Yeah, I have the libraries, it just looks like it can’t find them.
Right now I’ve copied the glue SO files from /Library/Frameworks/Mono.framework/Versions/2.10.9/lib to /Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib and this seems to resolve the namespace/location issue. (I tried editing Unity’s mono config file (mono/etc/config) to include DLL maps to the SOs but this didn’t seem to do anything)
Of course, Unity crashes when I invoke Gtk, so, I seem to still be missing something. Perhaps I am using the wrong version of the libraries.
It should support the same version or higher of Gtk+ if the Mono libraries track Gtk+ versions. So Gtk# and glue libs 2.10.0 should work with Gtk+ 2.10.0 or higher (as long as they’re within the 2.x line).
Well, I figured out the first issue with the Not Found errors. Solution:
Copy the GTK wrapper DLLs from /Library/Frameworks/Mono.framework/Versions/2.10/lib/mono/gtk-sharp-2.0 to your project (Plugins, presumably).
Then edit /Applications/Unity/Unity.app/Contents/Frameworks/Mono/etc/mono/config and add the references to the actual GTK SO files from the 2.10 install. In particular, I added
Then restart Unity so that it picks up on the references.
I even got a Gtk window to appear!
Unfortunately the Gtk loop seems to be interfering with Unity in some way, so, once I do Gtk.Application.Run() Unity appears to lock up but it looks like it’s just waiting on the Gtk main loop to finish or something like that.
One attempt has been to Init GTK and instead of calling Run, pump the event loop in a co-routine. For example:
class InterpreterTest1 (MonoBehaviour):
def _create_window():
w = Window("test window")
b = Button("click me")
b.Clicked += EventHandler(_click_event)
w.Add(b)
w.ShowAll()
static def _click_event(obj as object, args as EventArgs):
Debug.Log("You clicked on the button.")
def _pump_gtk():
while true:
if Gtk.Application.EventsPending():
Gtk.Application.RunIteration()
yield
def Start():
Gtk.Application.Init()
StartCoroutine("_pump_gtk")
def OnApplicationQuit():
Gtk.Application.Quit()
This, however, has some issues with Gtk that I haven’t figured out, namely, that Gtk thinks there is no main loop and trips a bunch of asserts. (Gtk-CRITICAL **: gtk_main_quit: assertion `main_loops != NULL’ failed) This isn’t really related to Unity at all.
So, then I figured, well, I’ll just put it in a Thread. Except that this has similar problems but also trips up Unity. When Gtk.Widget:gtk_widget_show_all(IntPtr) is called, it kicks off an “ArgumentException: CompareBaseObjectsInternal can only be called from the main thread.” error that is related to the Editor losing focus after the native call, along with a bunch of Gtk context errors.
class InterpreterTest2 (MonoBehaviour):
def _create_window():
def _helper():
Gtk.Application.Init()
w = Window("hi")
b = Button("print")
b.Clicked += EventHandler(_click_event)
w.Add(b)
w.ShowAll()
Gtk.Application.Run()
t = Thread(ThreadStart(_helper))
t.Start()
static def _click_event(obj as object, args as EventArgs):
Debug.Log("You clicked on the button.")
def OnApplicationQuit():
def _helper():
Gtk.Application.Quit()
Gtk.Application.Invoke(_helper)