-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
With DebugAllocator on, FMLEarlyWindow: The memory address specified is not being tracked #233
Comments
We might just use |
That would never do. |
The created Buffer holds a strong reference to the ByteBuffer so I am not sure how you draw the conclusion you need any special code to keep the backing memory alive. |
You are half right, GLFWImage.Buffer holds the ByteBuffer, but the native method won't. For example, if you wrote ByteBuffer buffer = BufferUtils.createByteBuffer(...); // a direct buffer that is subject to GC
glBufferData(GL_ARRAY_BUFFER, buffer, GL_DYNAMIC_DRAW); // any native method, or glfwSetWindowIcon in your case
// no more strong reference to the buffer this has a low chance of causing an ACCESS VIOLATION, because the native method only gets the 64-bit address value from the direct buffer, and thus it needs a reachability fence. You can think it's long addr = memAddress(buffer);
int size = buffer.remaining();
// no more strong reference to the buffer, GC may free the buffer here
// ok, addr may be a dangling pointer
glBufferData(GL_ARRAY_BUFFER, addr, size, GL_DYNAMIC_DRAW); That's also why all getXX() methods in DirectByteBuffer are similar to the following public char getChar() {
try {
return getChar(ix(nextGetIndex((1 << 1))));
} finally {
Reference.reachabilityFence(this);
}
} But these are not needed if using MemoryUtil.memAlloc, as the addresses must be explicitly freed. So LWJGL recommends MemoryUtil. |
Description:
Developers may want to track memory leaks. When started with
Dorg.lwjgl.util.DebugAllocator=true
andearlyWindowProvider = "fmlearlywindow"
, the game would crash atFancyModLoader/earlydisplay/src/main/java/net/neoforged/fml/earlydisplay/DisplayWindow.java
Line 457 in 05a7b82
Reason:
MemoryUtil.getAllocator()
returns a non-debug allocator (which won't track memory allocation), andStructBuffer.free()
via the try-with-resource statement calls toMemoryUtil.nmemFree()
which uses the debug allocator. Thenorg.lwjgl.system.MemoryManage.DebugAllocator.untrack()
will throw IllegalStateException which readThe memory address specified is not being tracked
.Solution:
Use
GLFWImage.malloc(1)
instead ofGLFWImage.create(MemoryUtil.getAllocator().malloc(GLFWImage.SIZEOF), 1)
Workaround:
Start with
earlyWindowProvider = "dummyprovider"
.The text was updated successfully, but these errors were encountered: