lwjgl3 icon indicating copy to clipboard operation
lwjgl3 copied to clipboard

X Error of failed request: BadWindow

Open Ali-RS opened this issue 3 years ago • 7 comments

Version

3.3.0 (nightly)

Platform

Linux x64

JDK

AdoptOpenJDK 16

Module

OpenGL, GLFW

Bug description

When I open a swing window 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 with jMonkeyEngine.

I am on Linux Mint with Mesa (v20) graphics driver.

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

Ali-RS avatar Mar 03 '22 08:03 Ali-RS

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.

httpdigest avatar Mar 03 '22 10:03 httpdigest

@httpdigest thanks for the response.

Afaik LWJGL recently added a modified version of GLFW (glfw_async) that makes it possible to use AWT/Swing together with GLFW on Mac. Should a similar solution work for Linux too?

Ali-RS avatar Mar 03 '22 11:03 Ali-RS

glfw_async currently only targets macOS. And it also does not allow you to create any AWT/Swing windows. It only lets you use the ImageIO subsystem (e.g. for image loading/storing) and lets you open/use modal dialog windows. glfw_async is basically there to avoid people who already use GLFW to add the -XstartOnFirstThread JVM argument.

httpdigest avatar Mar 03 '22 11:03 httpdigest

Hi! Another person trying to use AWT/Swing with LWJGL v3. 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 a problematic code snippet:

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

It appears that one of the requests for destroying a window from AWT is resulting in that error.

Some things I've observed from that example:

  • moving the GLFW initialization to be the first thing to run to prevent the error from popping and the application does not crash anymore.
  • I tried replacing the JFileChooser with a simple JDialog or JFrame and I couldn't get the error. It seems that there is something peculiar about JFileChooser that I've yet to identify.
  • The only thing we're doing in that example with GLFW is to initialize it. I'm curious to understand if this results in some sort of process being started in the native side that does some kind of maintenance or whatnot on its own.

I've been digging for solutions to get AWT/Swing to work with LWJGL v3, as migrating away from any of the two would result in a massive undertaking and does not seem like a viable solution at the moment.

SylvainBertrand avatar Mar 09 '22 16:03 SylvainBertrand

Making progress on the problematic example and found out that the drag and drop feature from Swing seems to be causing some trouble.

package example;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.TransferHandler;
import javax.swing.WindowConstants;

import org.lwjgl.glfw.GLFW;

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

      GLFW.glfwInit();

      TransferHandler newHandler = new TransferHandler("Bloppy");
      frame.setTransferHandler(newHandler); // Comment out to get the application to terminate properly.
      frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      frame.setLayout(new BorderLayout());
      frame.setPreferredSize(new Dimension(600, 600));
      frame.pack();
      frame.setVisible(true);
   }
}

As soon as a TransferHandler is added to the frame, the X Error of failed request: BadWindow will pop up and make the application crash immediately. No idea if that's useful observation but I'll keep digging unless someone has some further knowledge on the more general issue.

SylvainBertrand avatar Mar 10 '22 00:03 SylvainBertrand

That is platform dependent. You need set glfwGetX11Display and glfwGetX11Window with AWT/Swing and error will be gone.

For Windows glfwGetWin32Window and for macOS glfwCocoaWindow. Read more glfw3native!

Why do you not expect glfw with platform binding like SDL2 has also platform dependence Via SDL_GetWindowWMInfo?

DeafMan1983 avatar May 05 '22 05:05 DeafMan1983

Thanks @DeafMan1983

You need set glfwGetX11Display and glfwGetX11Window with AWT/Swing and error will be gone.

Not sure how to set these values, can you please show me the code snippet I need to add in my Java code? Thanks!

Ali-RS avatar May 05 '22 09:05 Ali-RS

Hey @Ali-RS & @SylvainBertrand,

Could you please try again with the latest LWJGL snapshot? I cannot reproduce such a crash. I also tried both code snippets by @SylvainBertrand and they worked without issues.

Spasi avatar Aug 22 '22 17:08 Spasi

Hi @Spasi

Thanks for your response. I can confirm using the latest snapshot the error does not occur.

Ali-RS avatar Aug 22 '22 18:08 Ali-RS

Sorry for late delay! Find in glfw native / platform check lwjgl3 packages

You should read glfw3 documentation for platform / native

DeafMan1983 avatar Mar 11 '23 17:03 DeafMan1983