jmonkeyengine icon indicating copy to clipboard operation
jmonkeyengine copied to clipboard

TestAWTPanels crashes with LWJGL v3 on Linux

Open stephengold opened this issue 3 years ago • 5 comments

With "jme3-lwjgl3" in JME v3.4.0-beta4, TestAWTPanels hangs. No output is generated, and no window appears.

Debugger suggests a deadlock, with the "jME Main" thread parked in line 103:

            panelsAreReady.await();

stephengold avatar May 15 '21 05:05 stephengold

This issue dates back at least to JME v3.2.4-stable.

stephengold avatar May 15 '21 06:05 stephengold

When I tested #1690 I accidentally used LWJGL v2 instead of LWJGL v3.

I just re-tested TestAWTPanels on Linux with LWJGL v3.3.0 and latest "master". I got the following crash:

> Task :jme3-examples:run
[ALSOFT] (EE) Failed to set real-time priority for thread: Operation not permitted (1)
[ALSOFT] (EE) Failed to set real-time priority for thread: Operation not permitted (1)
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f59932effc4, pid=9041, tid=0x00007f5965790700
#
# JRE version: OpenJDK Runtime Environment (8.0_212-b04) (build 1.8.0_212-b04)
# Java VM: OpenJDK 64-Bit Server VM (25.212-b04 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libpthread.so.0+0xbfc4]  pthread_mutex_lock+0x4
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/sgold/Git/jmonkeyengine/jme3-examples/hs_err_pid9041.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

> Task :jme3-examples:run FAILED

Here's the stack trace from hs_err_pid9041.log:

Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libpthread.so.0+0xbfc4]  pthread_mutex_lock+0x4
C  0x0000000000000000

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  sun.awt.X11.XlibWrapper.XGetDefault(JLjava/lang/String;Ljava/lang/String;)Ljava/lang/String;+0
j  sun.awt.X11.XToolkit.initializeMultiClickTime()V+12
j  sun.awt.X11.XToolkit.getMultiClickTime()I+6
j  sun.awt.X11.XToolkit.initializeDesktopProperties()V+82
j  java.awt.Toolkit.getDesktopProperty(Ljava/lang/String;)Ljava/lang/Object;+32
j  sun.swing.SwingUtilities2$AATextInfo.getAATextInfo(Z)Lsun/swing/SwingUtilities2$AATextInfo;+11
j  javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(Ljavax/swing/UIDefaults;)V+12062
j  javax.swing.plaf.basic.BasicLookAndFeel.getDefaults()Ljavax/swing/UIDefaults;+25
j  javax.swing.plaf.metal.MetalLookAndFeel.getDefaults()Ljavax/swing/UIDefaults;+9
j  javax.swing.UIManager.setLookAndFeel(Ljavax/swing/LookAndFeel;)V+79
j  javax.swing.UIManager.setLookAndFeel(Ljava/lang/String;)V+16
j  javax.swing.UIManager.initializeDefaultLAF(Ljava/util/Properties;)V+55
j  javax.swing.UIManager.initialize()V+9
j  javax.swing.UIManager.maybeInitialize()V+22
j  javax.swing.UIManager.getUI(Ljavax/swing/JComponent;)Ljavax/swing/plaf/ComponentUI;+0
j  javax.swing.JPanel.updateUI()V+2
j  javax.swing.JPanel.<init>(Ljava/awt/LayoutManager;Z)V+24
j  javax.swing.JPanel.<init>(Z)V+9
j  javax.swing.JPanel.<init>()V+2
j  javax.swing.JRootPane.createGlassPane()Ljava/awt/Component;+4
j  javax.swing.JRootPane.<init>()V+11
j  javax.swing.JFrame.createRootPane()Ljavax/swing/JRootPane;+4
j  javax.swing.JFrame.frameInit()V+16
j  javax.swing.JFrame.<init>(Ljava/lang/String;)V+21
j  jme3test.awt.TestAwtPanels.createWindowForPanel(Lcom/jme3/system/awt/AwtPanel;I)V+23
j  jme3test.awt.TestAwtPanels.access$400(Lcom/jme3/system/awt/AwtPanel;I)V+2
j  jme3test.awt.TestAwtPanels$2.run()V+94
j  java.awt.event.InvocationEvent.dispatch()V+47
j  java.awt.EventQueue.dispatchEventImpl(Ljava/awt/AWTEvent;Ljava/lang/Object;)V+21
j  java.awt.EventQueue.access$500(Ljava/awt/EventQueue;Ljava/awt/AWTEvent;Ljava/lang/Object;)V+3
j  java.awt.EventQueue$3.run()Ljava/lang/Void;+32
j  java.awt.EventQueue$3.run()Ljava/lang/Object;+1
v  ~StubRoutines::call_stub
j  java.security.AccessController.doPrivileged(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;+0
j  java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Ljava/security/PrivilegedAction;Ljava/security/AccessControlContext;Ljava/security/AccessControlContext;)Ljava/lang/Object;+18
j  java.awt.EventQueue.dispatchEvent(Ljava/awt/AWTEvent;)V+46
j  java.awt.EventDispatchThread.pumpOneEventForFilters(I)V+140
j  java.awt.EventDispatchThread.pumpEventsForFilter(ILjava/awt/Conditional;Ljava/awt/EventFilter;)V+35
j  java.awt.EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V+11
j  java.awt.EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V+4
j  java.awt.EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V+3
j  java.awt.EventDispatchThread.run()V+9
v  ~StubRoutines::call_stub

stephengold avatar Dec 06 '21 23:12 stephengold

The ALSOFT warnings will be removed in the next release of openal-soft: https://github.com/kcat/openal-soft/issues/554

Updating LWJGL to v3.3.0 included updating OpenAL Soft to v1.21.1, which might be relevant.

stephengold avatar Dec 07 '21 08:12 stephengold

I re-tested TestAWTPanels on Windows 10 with LWJGL v3.3.0 and latest "master". That seems to work fine, so the libpthread crash may be only on Linux.

stephengold avatar Dec 08 '21 22:12 stephengold

I discovered that commenting out the Thread.sleep(2000) section avoids the libpthread crash on Linux with LWJGL v3.3.0 . This leads me suspect there's a race condition, but I've no idea how to resolve it.

stephengold avatar Jan 07 '22 19:01 stephengold

Testing with JME 3.6.0-beta1 and LWJGL 3 on Linux I am also getting this exception in addition to the above JVM crash:

> Task :TestAwtPanels.main()
Feb 09, 2023 1:45:24 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.6.0-beta1
 * Branch: HEAD
 * Git Hash: ee91fb8
 * Build Date: 2023-01-24
Feb 09, 2023 1:45:25 PM com.jme3.app.LegacyApplication handleError
SEVERE: Failed to create display
java.lang.IllegalStateException
	at com.jme3.system.awt.AwtPanelsContext$AwtPanelsListener.reshape(AwtPanelsContext.java:67)
	at com.jme3.system.lwjgl.LwjglWindow.updateSizes(LwjglWindow.java:393)
	at com.jme3.system.lwjgl.LwjglWindow.createContext(LwjglWindow.java:370)
	at com.jme3.system.lwjgl.LwjglWindow.initInThread(LwjglWindow.java:582)
	at com.jme3.system.lwjgl.LwjglWindow.run(LwjglWindow.java:704)
	at java.lang.Thread.run(Thread.java:750)

https://github.com/jMonkeyEngine/jmonkeyengine/blob/925ff4561b29fff22fe2e47ecc63d129cb3a4000/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java#L65-L68

Ali-RS avatar Feb 09 '23 10:02 Ali-RS

Testing with JME 3.5.2-stable, I discovered setting app.setShowSettings(true); prevents the JVM crash, and the test works fine.

Edit: Also, discovered creating a dummy JFrame object (JFrame dummy = new JFrame();) before calling to app.start() will also prevent the JVM crash!

Ali-RS avatar Feb 09 '23 14:02 Ali-RS

Ok, further investigating I discovered adding either of the below codes resolves the issue:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

or just simply calling

UIManager.getLookAndFeel()

We should add it somewhere in the main methods (can be before or after calling to app.start()).

We still need to figure out how to fix the https://github.com/jMonkeyEngine/jmonkeyengine/issues/1558#issuecomment-1423951041 (IllegalStateException in JME 3.6.0-beta1)

Ali-RS avatar Feb 09 '23 18:02 Ali-RS

Submitted a fix: #1944

We still need to figure out how to fix the https://github.com/jMonkeyEngine/jmonkeyengine/issues/1558#issuecomment-1423951041 (IllegalStateException in JME 3.6.0-beta1)

Opened a new issue to track this: https://github.com/jMonkeyEngine/jmonkeyengine/issues/1945

Ali-RS avatar Feb 09 '23 19:02 Ali-RS

@stephengold can you please test this from the current master?

Ali-RS avatar Feb 12 '23 05:02 Ali-RS

I tested current "master" with LWJGL v3 on Linux, and there was no crash or hang. However, there were a couple unfamiliar log messages:

Feb 12, 2023 10:05:57 AM com.jme3.system.awt.AwtPanelsContext$AwtPanelsListener reshape
SEVERE: reshape is not supported.
[ALSOFT] (EE) Failed to set real-time priority for thread: Operation not permitted (1)
[ALSOFT] (EE) Failed to set real-time priority for thread: Operation not permitted (1)
OGL: Throttling update loop.
OGL: Ceased throttling update loop.
Feb 12, 2023 10:06:16 AM com.jme3.system.awt.AwtPanel drawFrameInThread
WARNING: OGL: DrawGraphics was null.

I'm unsure how important those diagnostics are.

stephengold avatar Feb 12 '23 18:02 stephengold

Thanks for testing

Not sure about others but SEVERE: reshape is not supported. will disappear once https://github.com/jMonkeyEngine/jmonkeyengine/pull/1950 is merged :)

Edit:

And OGL logs come from AwtPanelsContext: (however, I do not know what they mean!)

https://github.com/jMonkeyEngine/jmonkeyengine/blob/925ff4561b29fff22fe2e47ecc63d129cb3a4000/jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanelsContext.java#L218-L225

By the way, we should update it to use logger instead of System.out.println though!

Ali-RS avatar Feb 12 '23 18:02 Ali-RS