You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running with the debug allocator (-Dorg.lwjgl.util.DebugAllocator=true), Callback.free(functionPointer) may throw an exception if more than one thread is using MemoryManage at the same time. This is because we free up the memory in the real allocator before informing the debugger that it's free - and if something allocates memory inbetween these two statements on another thread, the debugger may consider this an invalid reallocation. Relevant lines: https://github.com/LWJGL/lwjgl3/blob/3.2.1/modules/lwjgl/core/src/main/java/org/lwjgl/system/Callback.java#L187-L194
I've noticed that elsewhere in MemoryTracker we do the opposite order of events: inform debugger that it's free, and then actually free it up. This avoids the problem, but technically is still vulnerable to a race condition: if something is actually allocated the same memory twice without freeing it, then the DebugAllocator won't notice.
This technically requires stb module, but anything that inherits from Callback will have the same problem (but I couldn't find a nice core Callback to demo with).
This code spawns 2 threads that will repeatedly allocate and free a Callback. If you run it with -Dorg.lwjgl.util.DebugAllocator=true, you should encounter the following crash:
Exception in thread "Thread-1" java.lang.IllegalStateException: The memory address specified is already being tracked: 0x1FC20000
at org.lwjgl.system.MemoryManage$DebugAllocator.track(MemoryManage.java:245)
at org.lwjgl.system.Callback.create(Callback.java:133)
at org.lwjgl.system.CallbackI.address(CallbackI.java:34)
at org.lwjgl.stb.STBIReadCallback.create(STBIReadCallback.java:52)
at com.mojang.CallbackRaceCondition.work(CallbackRaceCondition.java:17)
at java.lang.Thread.run(Thread.java:748)
The text was updated successfully, but these errors were encountered:
Environment
3.2.1
12
1.8.0_171
Windows, Linux & macOS
core
Description
When running with the debug allocator (
-Dorg.lwjgl.util.DebugAllocator=true
),Callback.free(functionPointer)
may throw an exception if more than one thread is usingMemoryManage
at the same time. This is because we free up the memory in the real allocator before informing the debugger that it's free - and if something allocates memory inbetween these two statements on another thread, the debugger may consider this an invalid reallocation. Relevant lines: https://github.com/LWJGL/lwjgl3/blob/3.2.1/modules/lwjgl/core/src/main/java/org/lwjgl/system/Callback.java#L187-L194I've noticed that elsewhere in
MemoryTracker
we do the opposite order of events: inform debugger that it's free, and then actually free it up. This avoids the problem, but technically is still vulnerable to a race condition: if something is actually allocated the same memory twice without freeing it, then the DebugAllocator won't notice.Reproducable example
This technically requires stb module, but anything that inherits from
Callback
will have the same problem (but I couldn't find a nice core Callback to demo with).This code spawns 2 threads that will repeatedly allocate and free a
Callback
. If you run it with-Dorg.lwjgl.util.DebugAllocator=true
, you should encounter the following crash:The text was updated successfully, but these errors were encountered: