I'm trying to get into Vulkan with LWJGL.
Currently I'm creating some sort of window (wrapper) class, however whenever i try to invoke glfwGetWindowSize
, glfwGetWindowPos
or glfwGetMonitorPos
the program crashes with a segmentation fault. The window creation itself works fine though, and i can also move the window programatically. I use default window hints (glfwDefaultWindowHints
).
The code:
var wbuf = IntBuffer.allocate(1);
var hbuf = IntBuffer.allocate(1);
glfwGetWindowSize(this.handle, wbuf, hbuf);
this.width = wbuf.get();
this.height = hbuf.get();
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f29938156b5, pid=13791, tid=13797
#
# JRE version: OpenJDK Runtime Environment Temurin-17.0.5+8 (17.0.5+8) (build 17.0.5+8)
# Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.5+8 (17.0.5+8, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# C [libglfw.so+0x156b5] glfwGetWindowSize+0x5
Environment: LWJGL v3.3.1 (with GLFW linux natives), Vulkan SDK v1.3.236.0 x86_64, Java 17 (Temurin), Fedora 36
As a side note: I'm also applying class loader tweaks before the GLFW init.
I was using non-direct buffers, while the LWJGL GLFW bidings only support direct ones.
Using direct buffers works fine:
try (var stack = MemoryStack.stackPush()) {
var width = stack.mallocInt(1);
var height = stack.mallocInt(1);
glfwGetWindowSize(this.handle, width, height);
this.width = width.get();
this.height = height.get();
}
MemoryUtil.memAllocInt(1)
and ByteBuffer.allocateDirect(4).asIntBuffer()
works as well.