Re: GTK is not correctly initialized

Greg Bowyer <[email protected]> Tue, 12 Jun 2007 18:11:25 +0100
Newsgroups gmane.comp.mozilla.devel.java
Message-ID <csSdnYfB5a6SSfPbnZ2dnUVZ_gWdnZ2d__1964.07761327482$1181668521$gmane$org@mozilla.org>
[email protected] wrote:
> Hi devs,
> 
> I'm currently experiencing some difficulties to manage to make gecko
> working with javaxpcom with a linux system.
> 
> I've browsed internet, read approximately everything that I could, and
> I finally understood the history of embedded gecko in applications.
> 
> But the problem is that many newbies  like me, have the initialization
> problem of gtk.
> 
> Here is the stack that I've got:
> 
> (process:27935): GLib-GObject-CRITICAL **: gtype.c:2242:
> initialization assertion failed, use IA__g_type_init() prior to this
> function
> 
> (process:27935): Gdk-CRITICAL **: gdk_screen_get_rgb_visual: assertion
> `GDK_IS_SCREEN (screen)' failed
> #
> # An unexpected error has been detected by HotSpot Virtual Machine:
> #
> #  SIGSEGV (0xb) at pc=0xa8c53727, pid=27935, tid=3085039296
> #
> # Java VM: Java HotSpot(TM) Client VM (1.5.0_11-b03 mixed mode)
> # Problematic frame:
> # C  [libxul.so+0xcb9727]  _ZN9nsToolkit14CreateSharedGCEv+0x23
> #
> # An error report file with more information is saved as
> hs_err_pid27935.log
> #
> # If you would like to submit a bug report, please visit:
> #   http://java.sun.com/webapps/bugreport/crash.jsp
> #
> 
> So I tried to change the version of the xpcom lib and used the one
> compiled for gtk, no way iit doesn't work.
> 
> So is anyone knows what I have to do? Do I have to configure something
> on my system, or add a library.
> 

Hey there, I too indeed have had this same problem. Basically what it 
boils down to is GTK is throwing its toys out of the pram when it comes 
to checking if it is initialised or not. What you need is someway to 
init gtk *before* you kick off mozilla.

I belive the bugs from the mozilla crew are
  * https://bugzilla.mozilla.org/show_bug.cgi?id=342691 and
  * https://bugzilla.mozilla.org/show_bug.cgi?id=343039

There are a couple of ways you can pull this off:
	1) Load up SWT as on linux this will kick off GTK+
	2) Ditto with Java-GTK
	3) Small method call to gtk_init in C land (welcome to JNI)

I used the last version and thus my code for this is something like

SNIP - C File
-------------------------------------------------------------------
#include <gtk/gtk.h>
#include "com_opodo_siterunner_xulrunner_GtkStub.h"

JNIEXPORT void JNICALL Java_com_opodo_siterunner_xulrunner_GtkStub_gtk_1init
   (JNIEnv *jniEnv, jclass clazz) {

	// the gdk / gtk code will function fine without this
	gtk_init(0, NULL);
}
-------------------------------------------------------------------

SNIP - Java Code
-------------------------------------------------------------------
public class GtkStub {

     /**
      * Method that, very basically calls gtk_init(0,NULL) in C land
      * so that GTK is correctly initalised for the XULRunner
      * application
      */
      private static native final void gtk_init();
}
-------------------------------------------------------------------