Bug 495896 - Embedded SWT_AWT frame crashes if Swing GTK LnF is used.
Summary: Embedded SWT_AWT frame crashes if Swing GTK LnF is used.
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.6   Edit
Hardware: PC Linux
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-10 13:08 EDT by Semyon Sadetsky CLA
Modified: 2021-01-07 19:21 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Semyon Sadetsky CLA 2016-06-10 13:08:28 EDT
The error output:

[xcb] Unknown sequence number while processing queue 
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called 
[xcb] Aborting, sorry about that. 
java: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed. 
Java Result: 134 

It looks like XInitThreads is not called, but SWT and AWT call Xlib concurrently.
Comment 1 Alexander Kurtakov CLA 2016-06-14 02:56:10 EDT
The reason for that is most probably that Swing GTK LnF loads gtk2 while SWT loads GTK3. To verify this is the case try starting with SWT_GTK3=0 env variable. Mixing the two gtk versions in the same process is a guarantee for disaster. This is a limitation on JVM side which can't be easily overcome (see http://openjdk.java.net/jeps/283 ) and staying on GTK2 by default is not an option for SWT as it means certain widgets not functioning anymore.
Recomendation would be to not use the Swing GTK LnF if using the SWT_AWT bridge.
Comment 2 Semyon Sadetsky CLA 2016-06-14 03:04:30 EDT
> The reason for that is most probably that Swing GTK LnF loads gtk2 while SWT loads GTK3.

It is not the case. The issue happens after GTK lib has been initialized. The app works some time and dies on random UI action.

The issue is reproducible with both GTK2 (SWT_GTK3=0) and GTK3. Also it is reproducible before and after JEP-283.
Comment 3 Alexander Kurtakov CLA 2016-06-14 03:21:11 EDT
Can you provide snippet reproducing the issue? (In reply to Semyon Sadetsky from comment #2)
> > The reason for that is most probably that Swing GTK LnF loads gtk2 while SWT loads GTK3.
> 
> It is not the case. The issue happens after GTK lib has been initialized.
> The app works some time and dies on random UI action.
> 
> The issue is reproducible with both GTK2 (SWT_GTK3=0) and GTK3. Also it is
> reproducible before and after JEP-283.

Is JEP-283 available in some Java 9 build? Asking cause on Fedora 24 trying to set Swing GTK LnF I get the regular mixture errors/crash

(SWT:5008): GLib-GObject-WARNING **: cannot register existing type 'GdkDisplayManager'

(SWT:5008): GLib-CRITICAL **: g_once_init_leave: assertion 'result != 0' failed
Comment 4 Semyon Sadetsky CLA 2016-06-14 04:28:10 EDT
> Can you provide snippet reproducing the issue?

public class SwingAppTest {

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        Thread.sleep(2000);
        Thread thread = new Thread() {
            @Override
            public void run() {


                Display display;
                Shell shell;
                org.eclipse.swt.widgets.Button swtButton;
                Composite composite;
                Frame frame;
                JTabbedPane tabbedPane;

                display = new Display();
                shell = new Shell(display);
                shell.setText("AWT Test");
                org.eclipse.swt.layout.GridLayout gridlayout =
                        new org.eclipse.swt.layout.GridLayout();
                shell.setLayout(gridlayout);
                swtButton = new org.eclipse.swt.widgets.Button(shell, SWT.PUSH);
                swtButton.setText("SWTButton");
                composite = new Composite(shell, SWT.EMBEDDED);
                composite.setLayoutData(new GridData(GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL));
                composite.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
                frame = SWT_AWT.new_Frame(composite);

                frame.setLayout(new java.awt.BorderLayout());
                Panel panel = new Panel();
                panel.setLayout(new java.awt.BorderLayout());

                tabbedPane = new JTabbedPane(JTabbedPane.TOP);
                tabbedPane.add("InternalFrame Test", new DesktopPanePanel());

                tabbedPane.add("SplitPane Test", new SplitPanePanel());
                panel.add(tabbedPane);

                frame.add(panel);

                shell.setLocation(10, 10);
                shell.setSize(600, 600);
                shell.open();
                while (!shell.isDisposed()) {
                    if (!display.readAndDispatch()) display.sleep();
                }
            }
        };
        thread.start();
        thread.join();

    }
}

Please note: You may need several attempts to make this UI running. 
Then do several action in the embedded Swing UI.

JEP-283 is available from JDK9 build 120. But you don't need JDK9. The bug is filed against JDK8.
Comment 5 Alexander Kurtakov CLA 2019-01-30 08:04:59 EST
Can you still reproduce this one with Java 11 and SWT 4.10 ?
Comment 6 Eric Williams CLA 2019-09-18 09:40:02 EDT
(In reply to Alexander Kurtakov from comment #5)
> Can you still reproduce this one with Java 11 and SWT 4.10 ?

Ping, any update?
Comment 7 Serhiy _ CLA 2020-07-29 20:11:48 EDT
I've started getting similar crashes on Eclipse launch after upgrading to 4.16.0.v20200604-0540 today on Kubuntu 20.04. It was just freezing at first and I started launching it from CLI. At first I didn't notice anything but then there was an X Error:

$ eclipse
(Eclipse:732750): Gdk-ERROR **: 03:09:29.937: The program 'Eclipse' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadLength (poly request too large or internal Xlib length erro'.
  (Details: serial 7808 error_code 16 request_code 139 (RENDER) minor_code 33)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

$ GDK_SYNCHRONIZE=1 eclipse
[xcb] Unknown sequence number while processing reply
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
java: ../../src/xcb_io.c:641: _XReply: Не пройдено перевірку «!xcb_xlib_threads_sequence_lost».
Comment 8 Serhiy _ CLA 2020-07-29 20:14:14 EDT
This seems related: https://bugs.eclipse.org/bugs/show_bug.cgi?id=454708
Comment 9 Serhiy _ CLA 2020-10-18 19:41:49 EDT
Today it no longer crashes. Maybe it was something in other packages.
Comment 10 Alexander Kurtakov CLA 2020-10-19 04:51:37 EDT
Marking as resolved as the original reporter didn't reply and latest one no longer face the issue.
Comment 11 Serhiy _ CLA 2021-01-07 19:21:08 EST
Looks like related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=568859