question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VulkanBuffer pointer never cleaned up / JVM Heap corruption

See original GitHub issue

After 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:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lwjglgamedevcommented, Jul 23, 2022

Just updated the code. I do like the approach of tightly controlling allocations and deallocations.

1reaction
lwjglgamedevcommented, Jun 24, 2022

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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can a corrupted heap be cleaned up? - Stack Overflow
If I corrupt my heap, can I clean it up afterwards? No you can't fix this. Basically your program has undefined behavior. A...
Read more >
C2M1212 Message - IBM
Clean up the memory problem if possible. When a C2M1212 message is generated, the hexadecimal value of the pointer passed to the free()...
Read more >
Solving a Mysterious Heap Corruption Crash
A while back, we noticed an increase in crashes in our app. The crashes were marked as heap corruption, which makes them hard...
Read more >
Review assimp flags,about lwjglgamedev/vulkanbook - Coder Social
... VulkanBuffer pointer never cleaned up / JVM Heap corruption HOT 5; Modal does not render correctly when using multiple `begin` HOT 6 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found