VulkanBuffer pointer never cleaned up / JVM Heap corruption
See original GitHub issueAfter playing with the VulkanBuffer implementation, I noticed that the pb
pointer buffer is never cleaned up. I tried adding pb.free()
to the cleanup, but after many VulkanBuffer allocation and deallocations, the JVM heap will become corrupt.
To fix this, I replaced PointerBuffer.allocateDirect(1);
with MemoryUtil.memAllocPointer(1);
/MemoryUtil.memFree(pointerBuffer);
inside the vulkan buffer class. The mem free is called on the cleanup of the vulkan buffer.
I have no idea or explination as to why the allocate direct causes the jvm heap to become corrupt. But when creating a large number of buffers, then destroying them, the jvm will crash with error 0xC0000374
and not produce any crash log or memory dump. I found the problem by using the LWJGLX debug agent, and it flagged the buffer on the added pb.free()
as being non-lwjgl tracked memory.
I originally discovered this in my own application, and checked the code here as I often use this project as a reference. I created a thread with more information on the lwjgl forums: http://forum.lwjgl.org/index.php?topic=7233.msg37410#new
I’m interested to know what you think about why the pb.free()
would cause the issue, and am curious if that is why you never included it in the cleanup, or if there is a larger reason that it is not included in the cleanup that I am missing.
I (re)discovered that direct allocated buffers are handled by GC.
Thanks, Trevor
EDIT: I have opened a LWJGL issue: https://github.com/LWJGL/lwjgl3/issues/775
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Just updated the code. I do like the approach of tightly controlling allocations and deallocations.
Hi, yes, I need to change that. I will update the code as soon as I can. Thanks for reporting, I should have detected that, but I always tend to forget that not using MemoryUtil prevents tracking…