jMonkeyEngine / jmonkeyengine

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

X Error of failed request: BadWindow (invalid Window parameter) with LWJGL3 #1778

Closed Ali-RS closed 1 year ago

Ali-RS commented 2 years ago

Platform

Linux Mint x64 with Mesa (v20) graphics driver

JDK

AdoptOpenJDK 16

Bug description

When I open a swing window (e.g. JME error dialog) along with the GLFW window, the moment I close the swing window it crashes the app with the below error. I am using LWJGL 3.

Stacktrace or crash log output

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  20 (X_GetProperty)
  Resource id in failed request:  0x4e0005b
  Serial number of failed request:  1332
  Current serial number in output stream:  1332
stephengold commented 2 years ago

Is this a regression, or did JME 3.4.1-stable have the same issue?

Ali-RS commented 2 years ago

I believe it is not a regression. I can reproduce it with older versions too.

For what it worth, I have also submitted an issue on the LWJGL GitHub page: https://github.com/LWJGL/lwjgl3/issues/742

Got this response:

Using AWT/Swing together with GLFW is not really supported/possible, because both try to steal each other's OS/window message events. AWT is using its own window message loop to process the OS/window message events in its EDT thread and you are doing the same with glfwPollEvents/glfwWaitEvents.

SylvainBertrand commented 2 years ago

Hi! I'm also struggling with the transition to LWJGL3 for an application of our own that uses JME and AWT/Swing. I've been trying to figure out various code examples that cause an application to crash when running on Linux (testing on Ubuntu 20.04) with Java 17 (using Azul Zulu OpenJDK 17.0.2). Here's one example that seems similar to what you're experiencing @Ali-RS :

package example;

import javax.swing.JFileChooser;
import javax.swing.JFrame;

import org.lwjgl.glfw.GLFW;

public class CodeSnippet
{
   public static void main(String[] args)
   {
      new JFrame();

      GLFW.glfwInit();

      new JFileChooser().showOpenDialog(null);
   }
}

When closing the dialog to open a file, the whole app terminates immediately with the following error message:

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  20 (X_GetProperty)
  Resource id in failed request:  0x4a00020
  Serial number of failed request:  1515
  Current serial number in output stream:  1515

In this example, it seems enough to move the GLFW initialization to be the first thing to run to prevent the error from popping.

I'm still digging for solutions, as migrating away from Swing/AWT or JME is not viable solution for me.

Ali-RS commented 2 years ago

In this example, it seems enough to move the GLFW initialization to be the first thing to run to prevent the error from popping.

That's interesting!

If I disable the JME Settings dialog with app.setShowSettings(false); (so GLFW will be the first thing to get initialized) then opening/closing a Swing window after that seems to be working fine in my case as well.

@SylvainBertrand thanks for the update!

Ali-RS commented 2 years ago

The error does not occur with the latest snapshot build (3.3.2 SNAPSHOT build 2) of LWJGL3.

Ali-RS commented 1 year ago

Fixed by https://github.com/jMonkeyEngine/jmonkeyengine/commit/76ebd1443ccc18249e9f082d528cd39baf59da84