Main Menu

Recent posts

#1
Bug Reports / RFE / Segfault, but only when runnin...
Last post by ryanm - October 21, 2025, 21:14:29
This is the most cornery of corner cases, but I'm experiencing a segfault that only happens when I run my game via steam, and on linux.
It can be reliably triggered by changing the display parameters that require me to tear down and recreate the window - you can do this with no issue up to three times, but the fourth will provoke a segfault.

I've cut things down to this minimal case:

  public static void main(String[] args) {
    if (!glfwInit()) {
      throw new IllegalStateException("Unable to initialize GLFW");
    }

    long window = createWindow();

    for (int i = 0; i < 10; i++) {
      LOG.info("iteration {}", i);
      try {
        Thread.sleep(100); // allowing logging to flush
      } catch (InterruptedException ie) {
      }
      GLFW.glfwDestroyWindow(window);
      window = createWindow();
      GLFW.glfwPollEvents();
      GLFW.glfwSwapBuffers(window);
    }
    LOG.info("normal exit");
  }

  private static long createWindow() {
    long window = glfwCreateWindow(640, 480, "title", NULL, NULL);
    glfwMakeContextCurrent(window);
    glfwShowWindow(window);
    return window;
  }

If I run that directly from the IDE, it completes normally. If I run it from steam (which presumably brings steam's overlay stuff into play), it'll segfault on the 4th iteration.

Interestingly, commenting out the
GLFW.glfwPollEvents()
call allows normal exit - no segfault is provoked.

I'd like to attach the hs_err_pid file, but that provokes an error from the forum. The summary of the dump is:
---------------  S U M M A R Y ------------

Command Line: -Djdk.module.main=dev.flowty.trace dev.flowty.trace/dev.flowty.trace.Main

Host: AMD Custom APU 0405, 8 cores, 14G, Steam Runtime 2 (soldier)
Time: Tue Oct 21 21:54:24 2025 IST elapsed time: 1.040722 seconds (0d 0h 0m 1s)

---------------  T H R E A D  ---------------

Current thread (0x00007fb63002c110):  JavaThread "main"             [_thread_in_native, id=31412, stack(0x00007fb637500000,0x00007fb637600000) (1024K)]

Stack: [0x00007fb637500000,0x00007fb637600000],  sp=0x00007fb6375f9bd0,  free space=998k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [gameoverlayrenderer.so+0x499b9]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.lwjgl.system.JNI.invokePV(JJ)V+0 org.lwjgl@3.3.6+1
j  org.lwjgl.glfw.GLFW.glfwSwapBuffers(J)V+17 org.lwjgl.glfw@3.3.6+1
j  dev.flowty.trace.Main.main([Ljava/lang/String;)V+65 dev.flowty.trace@0.0.1-SNAPSHOT
v  ~StubRoutines::call_stub 0x00007fb622537cc6

Can anyone spot what I'm doing wrong?

Cheers!
#2
Lightweight Java Gaming Library / Re: Crash during allocation of...
Last post by cpope9141 - September 01, 2025, 13:18:16
Thank you for your help, spasi!
#3
Lightweight Java Gaming Library / Re: Crash during allocation of...
Last post by spasi - September 01, 2025, 08:15:51
No timeline yet. I think you only need lwjgl-vulkan.jar and it should work fine with the 3.3.6 core. However, I don't see a reason to not switch to 3.4.0-snapshot altogether. LWJGL snapshots are very stable due to its nature: most changes happen in the bindings & native libraries and those are always stable releases.

QuoteMemoryStack stack = MemoryStack.create(capacity).push(); {
//use stack
} stack.pop();
This will work, but it's wasteful (a GC-managed ByteBuffer is allocated internally). I would recommend sticking to the default stack for everything, except the extension properties array. This is what LWJGL does now:

try (VkExtensionProperties.Buffer extensions = VkExtensionProperties.malloc(capacity)) {
  // ...
}
This does explicit malloc/free.
#4
Do you have a timeline for when the 3.4.0-snapshot will be upgraded to release? If not soon, how much of a risk would it be for me to use the snapshots of lwjgl.jar and lwjgl-vulkan.jar in their current state?
#5
So, I need to set the stack capacity with something like:

MemoryStack stack = MemoryStack.create(capacity).push(); {
//use stack
} stack.pop();

The above seems to be working for me, but I'd be happy for someone to double check that I am not misusing something.
#6
Lightweight Java Gaming Library / Re: Crash during allocation of...
Last post by spasi - August 31, 2025, 21:14:21
That's the same bug, just in your code instead of inside LWJGL. VkExtensionProperties is a relatively big struct (260 bytes), so 252 such structs make it easy to overflow the default MemoryStack size (64kb).
#7
I have updated lwjgl.jar (with natives) to 3.4.0-snapshot. Before updating my Nvidia driver, the game continued to work (as expected). After updating the driver, I see a crash and this stack trace:

Exception in thread "main" java.lang.OutOfMemoryError: Out of stack space.
    at org.lwjgl.system.MemoryStack.nmalloc(MemoryStack.java:321)
    at org.lwjgl.vulkan.VkExtensionProperties.malloc(VkExtensionProperties.java:208)
    at org.lwjgl.vulkan.VkInstance.getAvailableDeviceExtensions(VkInstance.java:82)
    at org.lwjgl.vulkan.VkInstance.getInstanceCapabilities(VkInstance.java:45)
    at org.lwjgl.vulkan.VkInstance.<init>(VkInstance.java:29)
    at renderer.vulkan.VulkanInstance.create(VulkanInstance.java:77)
    at renderer.RendererCore.create(RendererCore.java:238)
    at renderer.Renderer.create(Renderer.java:544)
    at game.Game.run(Game.java:47)
    at game.Game.main(Game.java:15)

If I also update lwjgl-vulkan.jar to 3.4.0-snapshot, I continue to see a crash, but it is past the vulkan instance creation during physical device selection:

Exception in thread "main" java.lang.OutOfMemoryError: Out of stack space.
    at org.lwjgl.system.MemoryStack.nmalloc(MemoryStack.java:321)
    at org.lwjgl.vulkan.VkExtensionProperties.malloc(VkExtensionProperties.java:200)
    at renderer.vulkan.physicalDevice.PhysicalDevice.checkDeviceExtensionSupport(PhysicalDevice.java:156)
    at renderer.vulkan.physicalDevice.PhysicalDevice.meetsRequirments(PhysicalDevice.java:234)
    at renderer.vulkan.physicalDevice.PhysicalDevice.selectPhysicalDevice(PhysicalDevice.java:119)
    at renderer.RendererCore.create(RendererCore.java:239)
    at renderer.Renderer.create(Renderer.java:544)
    at game.Game.run(Game.java:47)
    at game.Game.main(Game.java:15)

I am using "try(MemoryStack stack = stackPush())" to create the stack passed into VkExtensionProperties.malloc. It appears that the capacity being requested from the stack at the time of the crash is only (252 * SIZEOF).
#8
Lightweight Java Gaming Library / Re: Crash during allocation of...
Last post by spasi - August 29, 2025, 17:27:20
Yes, the extensions array is now allocated normally.
#9
Thanks for the response spasi.

It appears I may be experiencing the same crash after updating my NVIDA driver. Rolling back the driver to what was previously installed stops the crash from occurring. Is this consistent with the "fix(Vulkan) VkExtensionProperties array allocation" commit? That is, would the updated driver be returning an array of extensions too large to be allocated on the stack?
#10
Lightweight Java Gaming Library / Re: Crash during allocation of...
Last post by spasi - August 28, 2025, 16:56:49
Hey cpope9141,

Without a stacktrace to examine, I'd say you're hitting a known bug in LWJGL 3.3.6 that has been fixed with https://github.com/LWJGL/lwjgl3/commit/b5b363e2. Please try upgrading to 3.4.0-snapshot.