Re: jvm crash on ubuntu 8.10 with javaxpcom code

Greg Bowyer <[email protected]> Fri, 20 Mar 2009 15:10:08 +0000
Newsgroups gmane.comp.mozilla.devel.java
Message-ID <[email protected]>
<Posting this back to the dev list because other, wiser people will know 
more>

Could you point me to what ediutor interfaces you are looking at, largly 
what is exposed by java xpcom is actually the XPCOM system proper; that 
is its just a language bridge rather than anything specific to java 
bindings.

What do you mean by canvas ? the <canvas> tag ?

Is this the chrome (XUL) dom or a different content (say html) you are 
manipulating

I would probably need to see more of your code to work out what you are 
trying to do one the DOM direct from the underlying code, but my gut 
feel is that rather than do this from java, it would probably be a *lot* 
easier to do it in javascript

On 20/03/09 13:55, Gonzalo Tirapegui Medina wrote:
> Thanks Greg , i initialize the gtk context and the jvm's crash just 
> disappear. Now i have a question a little bit different .
> I'm planning to do some GUI Editor based on the editor interfaces of 
> java xpcom . The problem is the widgets that we will drop into the 
> Mozilla Canvas are composed by many nested DOM Objects , and The 
> selection Model of the Editor Interfaces is adapted to select just the 
> DOM object that we are clicking. Can you give me some orientation 
> about what interfaces i need to rewrite to select the "father" 
> component of the clicked Dom node , instead of just the Dom node itself?
>
> Regards , Gonzalo Tirapegui Medina
>
> 2009/3/20 Greg Bowyer <[email protected] 
> <mailto:[email protected]>>
>
>     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
>         <http://mozilla.org/toolkit/app-startup;1> service:
>         nsIAppStartup appStartup =
>         (nsIAppStartup)serviceManager.getServiceByContractID("@mozilla.org/toolkit/app-startup;1
>         <http://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
>         <http://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
>
>