General:
I always receive SIGSEGV on Linux when invoke the XRE_InitEmbedding2 function with XULRunner 15.
Details:
I'm trying to embed Mozilla (XULRunner 15.05b 64-bit) browser component into my GTK application on Fedora 12 64-bit. I created Eclipse project, configured it to use all required XULRunner libraries and include files and successfully built it.
Here's the application code:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include "nsXPCOM.h"
#include "nsXPCOMGlue.h"
#include "nsEmbedString.h"
#include "nsXULAppAPI.h"
#include "nsILocalFile.h"
using namespace std;
XRE_InitEmbedding2Type XRE_InitEmbedding2Delegate;
int main(int argc, char** argv) {
nsDynamicFunctionLoad kXRESymbols[] = {
{"XRE_InitEmbedding2", (NSFuncPtr*) &XRE_InitEmbedding2Delegate},
{0, 0}
};
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);
nsresult rv = XPCOMGlueStartup("/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/bin/libxpcom.so");
if (NS_FAILED(rv)) {
return rv;
}
rv = XPCOMGlueLoadXULFunctions(kXRESymbols);
if (NS_FAILED(rv)) {
return rv;
}
nsILocalFile *libXULDir;
rv = NS_NewNativeLocalFile(nsEmbedCString("/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/bin"), PR_FALSE, &libXULDir);
if (NS_FAILED(rv)) {
return rv;
}
rv = XRE_InitEmbedding2Delegate(libXULDir, libXULDir, nsnull);
if (NS_FAILED(rv)) {
return rv;
}
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
I compiled this application with the following command line:
make all
Building file: ../src/JavaXPCOMTest.cpp
Invoking: GCC C++ Compiler
g++ -DXPCOM_GLUE_USE_NSPR=1 -DXPCOM_GLUE=1 -I/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/include -I/usr/include/gtk-2.0 -I/usr/include/glib-2.0 -O0 -g3 -Wall -c -fmessage-length=0 -std=gnu++0x `pkg-config --cflags --libs gtk+-2.0` -MMD -MP -MF"src/JavaXPCOMTest.d" -MT"src/JavaXPCOMTest.d" -o"src/JavaXPCOMTest.o" "../src/JavaXPCOMTest.cpp"
Finished building: ../src/JavaXPCOMTest.cpp
Building target: JavaXPCOMTest
Invoking: GCC C++ Linker
g++ -L/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/lib -L/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/bin -Wl,-rpath-link,/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/bin -o"JavaXPCOMTest" ./src/JavaXPCOMTest.o -lxpcomglue -lstdc++ `pkg-config --cflags --libs gtk+-2.0`
Finished building target: JavaXPCOMTest
When I run this application I receive SIGSEGV when invoke the XRE_InitEmbedding2Delegate function with the following call stack:
Thread [1] 15449 (Suspended : Signal)
_dl_fixup() at 0x3dbd60dbec
_dl_runtime_resolve() at 0x3dbd614315
0x7fffee4031d3
0x7fffee429209
0x7fffee429223
0x7fffee42a943
0x7fffee42b7ae
0x7fffee42bb25
NS_InitXPCOM2_P() at 0x7fffee4063a9
XRE_InitEmbedding2() at 0x7fffed998ce7
<...more frames...>
Does anybody reproduced similar issue on Linux platform with XULRunner 15? Maybe I use some wrong command line parameters or forget to include something in command line.
It might be related to this unanswered bug report:
Since Firefox 10 we get a crash while creating (constructor) the MozApp-object. More precisely the crash is by calling the API 'XRE_InitEmbedding2()' (its function- pointer is valid!) ... Up to version 9 of Firefox we do not have this crash - only since version 10. You can find details in the following bug report here: https://bugzilla.mozilla.org/show_bug.cgi?id=724822
You might be able to use the Embedded API. But using gtkmozembed is doomed anyway, as the authors are withdrawing all support for it, so any problems that you find will not be fixed:
WebKitGTK is often used as an alternative browser component (based on WebKit), although I found it unstable for running the Adobe Flash plugin through NPAPI. If you can live with its limitations, gtkhtml is simpler and therefore more reliable, and may work better for you.
Finally, for anyone who arrived here looking for solutions to gtkmozembed crashing with SIGSEGV in xulrunner (as I did), the answer may be that you forgot to run your app through run-mozilla.sh
, which tells Mozilla where to find its components.