libgdx / libgdx

Desktop/Android/HTML5/iOS Java game development framework
http://www.libgdx.com/
Apache License 2.0
23.27k stars 6.43k forks source link

Desktop apps crash on Mac when window is moved around #6987

Closed Trurl101 closed 1 month ago

Trurl101 commented 2 years ago

Issue details

Desktop apps crash Mac OS when the window is moved around.

Sometimes it shows the following error: A command encoder is already encoding to this command buffer

Reproduction steps/code

Start a Desktop app on Mac OS and move the window around, after a few seconds the app crashes.

Workaround

Remove from build.file: implementation "com.badlogicgames.gdx:gdx-lwjgl3-glfw-awt-macos:$gdxVersion" And use -XstartOnFirstThread as VM option

Version of libGDX and/or relevant dependencies

1.11.1-SNAPSHOT Mac OS 12.6/M1 Mac I could not test it on Intel Mac but found a similar issue here and that happens only on M1: https://github.com/opentk/opentk/issues/1457

Please select the affected platforms

tommyettinger commented 1 year ago

I'm just using this code now, for what it's worth. It goes in the DesktopLauncher or Lwjgl3Launcher, before any GLFW calls are made. I'm not using gdx-lwjgl3-glfw-awt-macos at all, since this acts similarly. The glfw_async feature is relatively new in LWJGL3, so requires libGDX 1.11.0 or newer.

        if (SharedLibraryLoader.isMac && Gdx.app == null) {
            org.lwjgl.system.Configuration.GLFW_LIBRARY_NAME.set("glfw_async");
        }
tommyettinger commented 1 year ago

I'm just using this code now, for what it's worth. It goes in the DesktopLauncher or Lwjgl3Launcher, before any GLFW calls are made. I'm not using gdx-lwjgl3-glfw-awt-macos at all, since this acts similarly. The glfw_async feature is relatively new in LWJGL3, so requires libGDX 1.11.0 or newer.

      if (SharedLibraryLoader.isMac && Gdx.app == null) {
          org.lwjgl.system.Configuration.GLFW_LIBRARY_NAME.set("glfw_async");
      }

So this approach turns out to still have issues with resizing. I've been recommending using some form of this gist for a little while now, and gdx-liftoff includes that gist's code in LWJGL3 modules. On macOS, it automatically adds -XstartOnFirstThread so users don't need to mess with that, and doesn't need any extra dependencies or the glfw_async thing. That's all @crykn 's code from Guacamole. The part I added affects Windows, and allows users with non-ASCII usernames (and so non-ASCII paths for their default temp directory) to still run an LWJGL3 game, in at least most cases. Without something like this, a user with Turkish-specific letters in their username wouldn't be able to launch the game at all, and the same is true for some other languages.