Re: jvm crash on ubuntu 8.10 with javaxpcom code
Greg Bowyer <[email protected]> Fri, 20 Mar 2009 11:54:11 +0000
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Message-ID | <49C383E3.8070103__14634.0341693305$1237550188$gmane$org@fastmail.co.uk> |
On 09/03/09 03:15, Gonzalo Tirapegui wrote:
> Hi all
>
> i'm trying to run some examples of the javaxpcom interfaces , in order
> to do that , i've download the xulrunner-sdk tar and execute the
> following code :
>
>
> public class Main {
>
> public static class LocationProvider implements IAppFileLocProvider {
>
> File grePath;
>
> public LocationProvider(File grePath) {
> this.grePath = grePath;
> }
>
> public File getFile(String aProp, boolean[] aPersistent) {
> System.out.println(aProp);
> System.out.println(aPersistent);
>
> File file = null;
> if (aProp.equals("GreD") || aProp.equals("GreComsD")) {
> file = grePath;
> if (aProp.equals("GreComsD")) {
> file = new File(file, "components");
> }
> } else if (aProp.equals("MozBinD") || aProp.equals("CurProcD")
> || aProp.equals("ComsD") || aProp.equals("ProfD")) {
> file = grePath;
> if (aProp.equals("ComsD")) {
> file = new File(file, "components");
> }
> }
> return file;
> }
>
> public File[] getFiles(String aProp) {
> System.out.println(aProp);
>
> File[] files = null;
> if (aProp.equals("APluginsDL")) {
> files = new File[1];
> files[0] = new File(grePath, "plugins");
> }
> return files;
> }
> }
>
> public static void main(String[] args) {
>
> System.setProperty("GRE_HOME", "/home/teckla/core/xulrunner-sdk/bin");
> System.setProperty("java.library.path",
> "/home/teckla/core/xulrunner-sdk/bin");
>
> Mozilla mozilla = Mozilla.getInstance();
> GREVersionRange[] range = new GREVersionRange[1];
> range[0] = new GREVersionRange("1.8.0", true, "1.9", false);
> // work with trunk nightly version 1.9a1
> try {
> File grePath = Mozilla.getGREPathWithProperties(range, null);
> System.out.println(grePath.toString());
> mozilla.initialize(grePath);
> LocationProvider locProvider = new LocationProvider(grePath);
> mozilla.initEmbedding(grePath, grePath, locProvider);
>
> // Note, on linux, gtk has to be already initialized for this code to work
> Mozilla moz = Mozilla.getInstance();
> // Now we need to start an XUL application, so we get an instance of the
> XPCOM service manager
> nsIServiceManager serviceManager = moz.getServiceManager();
> // Now we need to get the @mozilla.org/toolkit/app-startup;1 service:
> nsIAppStartup appStartup =
> (nsIAppStartup)serviceManager.getServiceByContractID("@mozilla.org/toolkit/app-startup;1",
> nsIAppStartup.NS_IAPPSTARTUP_IID);
> // Get the nsIWindowWatcher interface to the above
> nsIWindowCreator windowCreator =
> (nsIWindowCreator)appStartup.queryInterface(nsIWindowCreator.NS_IWINDOWCREATOR_IID);
>
> // Get the window watcher service
> nsIWindowWatcher windowWatcher =
> (nsIWindowWatcher)serviceManager.getServiceByContractID("@mozilla.org/embedcomp/window-watcher;1",
> nsIWindowWatcher.NS_IWINDOWWATCHER_IID);
> // Set the window creator (from step 6)
> windowWatcher.setWindowCreator(windowCreator);
> // Create the root XUL window:
> nsIDOMWindow win = windowWatcher.openWindow(null,
> "chrome://your-app/content/window.xul", "mywindow",
> "chrome,resizable,centerscreen", null);
> // Set this as the active window
> windowWatcher.setActiveWindow(win);
> // Hand over the application to xpcom/xul, this will block:
> appStartup.run();
> } catch (FileNotFoundException e) {
> e.printStackTrace();
> } catch (XPCOMException e) {
> e.printStackTrace();
> }
>
> }
> }
>
>
>
> .... but by some reason , the jvm crash on the line :
>
> nsIDOMWindow win = windowWatcher.openWindow(null,
> "chrome://your-app/content/window.xul", "mywindow",
> "chrome,resizable,centerscreen", null);
>
> giving the following trace :
>
>
>
>
>
> (process:22320): GLib-GObject-CRITICAL **:
> /build/buildd/glib2.0-2.18.2/gobject/gtype.c:2458: initialization
> assertion failed, use IA__g_type_init() prior to this function
>
> (process:22320): GLib-CRITICAL **: g_once_init_leave: assertion
> `initialization_value != 0' failed
>
> (process:22320): Gdk-CRITICAL **: gdk_screen_get_rgb_visual: assertion
> `GDK_IS_SCREEN (screen)' failed
> #
> # An unexpected error has been detected by Java Runtime Environment:
> #
> # SIGSEGV (0xb) at pc=0x90209a6c, pid=22320, tid=3084917648
> #
> # Java VM: Java HotSpot(TM) Server VM (10.0-b23 mixed mode linux-x86)
> # Problematic frame:
> # C [libxul.so+0x84aa6c]
> #
> # An error report file with more information is saved as:
> # /home/teckla/Escritorio/lobobrowser
> tests/testxulrunner/hs_err_pid22320.log
> #
> # If you would like to submit a bug report, please visit:
> # http://java.sun.com/webapps/bugreport/crash.jsp
> # The crash happened outside the Java Virtual Machine in native code.
> # See problematic frame for where to report the bug.
> #
> Java Result: 134
>
>
>
> Can anyone help me with this issue?
>
>
> Regards , Gonzalo Tirapegui Medina
I am pretty sure your problem is that you have not initialised GTK
before you handed control over to the mozilla event loop. On *nix the
embedding toolkit does not take care of this for you (it does AFAIK take
care of it on windows and OSX).
see
https://bugzilla.mozilla.org/show_bug.cgi?id=342691 and
https://bugzilla.mozilla.org/show_bug.cgi?id=343039
for the full horror
You basically need a small GTK init stub like the one below in C to get
GTK fired up correctly, link this up with JNI and you should be good to go.
-----
- SNIP SNIP C code
-----
#include <gtk/gtk.h>
#include "com_bonsaichicken_siterunner_xulrunner_GtkStub.h"
/**
* Very very simple call that will shunt a GTK init on the C side
* of the JNI bridge
* this is a total hack to work around a know issue in XULRunner
* whereby it will not initialise on a linux box without GTK being
* pre-inited first
*
* note! this is *not* the official solution, that is coming when
* https://bugzilla.mozilla.org/show_bug.cgi?id=342691 and
* https://bugzilla.mozilla.org/show_bug.cgi?id=343039
* are resolved properly (then this fugly hack will melt away)
*
* @author Greg Bowyer
*/
JNIEXPORT void JNICALL
Java_com_bonsaichicken_siterunner_xulrunner_GtkStub_gtk_1init
(JNIEnv *jniEnv, jclass clazz) {
// Chances are that the following are not required,
// but in the case they maybe ....
// g_thread_init(NULL);
// gdk_threads_init();
// g_set_prgname("XULRunner-X11-Linux-JavaXPCom")
// Don't sweat passing in argc, argv its not required or
// xulrunner the gdk / gtk code will function fine without this
gtk_init(0, NULL);
}
---
- End of C code
---
Give us a shout if you need more help with this