1

I'm trying to port an SWT desktop application to Ubuntu. Have downloaded Eclipse Neon (6.4.2) for Ubuntu and swt-4.6.2-gtk-linux-x86_64.zip, configured libraries in the project build path to point to the swt.jar from the downloaded swt zip.
Eclipse works fine, the application gets compiled, but crashes when trying to execute the following line of the code:

    Display display = Display.getDefault();

It's the very first call to the SWT in the program.
Eclipse writes to console the following message :

(SWT:3351): GLib-GObject-WARNING **: cannot register existing type 'GdkDisplayManager'
(SWT:3351): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed
(SWT:3351): GLib-GObject-CRITICAL **: g_object_new: assertion 'G_TYPE_IS_OBJECT (object_type)' failed
(SWT:3351): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(SWT:3351): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
(SWT:3351): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(SWT:3351): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
(SWT:3351): GLib-GObject-WARNING **: cannot register existing type 'GdkDisplay'
(SWT:3351): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed
(SWT:3351): GLib-GObject-CRITICAL **: g_type_register_static: assertion 'parent_type > 0' failed
(SWT:3351): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed
(SWT:3351): GLib-GObject-CRITICAL **: g_object_new: assertion 'G_TYPE_IS_OBJECT (object_type)' failed
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f729ae932b7, pid=3351, tid=0x00007f72e24aa700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_111-b14) (build 1.8.0_111-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.111-b14 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libgdk-x11-2.0.so.0+0x4e2b7]  gdk_display_open+0x57
#

Ubuntu 16.04 LTS. Under Windows, the application works fine. What may be the reason and how can I fix it?

PS A rather strange thing. When it is packed to jar outside the Ubuntu (under Windows, along with the Linux SWT and Jar-in-Jar loader), this Jar starts to work under Ubuntu, exept the file open dialog, that draws just an empty window instead of the dialog. It behaves this way 2 (two) times. The third time I start it it crushes again with the same message ((SWT:3351): GLib-GObject-WARNING etc). Restarting Ubuntu and setting `SWT_GTK3=0' don't affect.

PPS Ubuntu is running in Hyper-V under Windows2008, if it matters...

m. vokhm
  • 669
  • 1
  • 6
  • 24

1 Answers1

1

In my case, actually, Baz was right in his comment to the question -- export SWT_GTK3=0 solves the issue. I just had to provide that it had an effect when Eclipse (or my app) starts -- either set it in ~/.profile or start Eclipse (or jar file with my app) from a bash script where this variable is previously set.

And there is a tidier way to get the desirable effect. As far as the SWT code is executed in the same JVM with the application, it is sufficient to set this variable programmatically only for specific JVM instance, either as an environment variable or as a system property, in any point of the code before the very first call to the SWT is done.

In my code, I do it simply:

  public static void main(String[] args) {
    System.setProperty("SWT_GTK3", "0");
    // now we can use SWT

After that, SWT works fine both from under Eclipse and from JAR file, without any need to use bash scripts or customize the user profile.

m. vokhm
  • 669
  • 1
  • 6
  • 24
  • In some cases (namely, if you want to use normal scrollbars instead of default "overlay csrollbars") SWT (more precisely, GTK) requires one more environment variable - `LIBOVERLAY_SCROLLBAR=0`. I've spent a couple of evenings to find a way to set it from java code, and I've found it: http://stackoverflow.com/questions/42048599/how-to-disable-overlay-scrollbars-programmatically-ubuntu-java – m. vokhm Feb 11 '17 at 15:33