我正在尝试使用LWJGL进入Vulkan。
目前我正在创建某种窗口(包装器)类,但是每当我试图调用glfwGetWindowSize
,glfwGetWindowPos
或glfwGetMonitorPos
程序崩溃与分割错误。虽然窗口创建本身工作得很好,但我也可以通过编程方式移动窗口。我使用默认的窗口提示(glfwDefaultWindowHints
)。
代码:
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
环境:LWJGL v3.3.1(与GLFW linux本机),Vulkan SDK v1.3.236.0 x86_64, Java 17 (Temurin), Fedora 36
作为旁注:我还在GLFW init之前应用类加载器调整。
我使用的是非直接缓冲区,而LWJGL GLFW绑定只支持直接缓冲区。
使用直接缓冲区也可以:
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)
和ByteBuffer.allocateDirect(4).asIntBuffer()
也可以。