jMonkeyEngine / jmonkeyengine

A complete 3-D game development suite written in Java.
http://jmonkeyengine.org
BSD 3-Clause "New" or "Revised" License
3.81k stars 1.12k forks source link

TestAWTPanels crashes with LWJGL v3 on Linux #1558

Closed stephengold closed 1 year ago

stephengold commented 3 years ago

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 commented 3 years ago

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

stephengold commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.

Ali-RS commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

stephengold commented 1 year ago

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.

Ali-RS commented 1 year ago

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!