Max ids
Closed this issue · 7 comments
Hi !
I have a problem when I have more than 512 ids used in the same time.
I've got this when I for example draw 2 windows that need to draw a lot of image buttons.
The stacktrace :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 512
at imgui.internal.Window.getId(classes.kt:560)
at imgui.imgui.imgui_idScopes$DefaultImpls.pushId(id scopes.kt:19)
at imgui.ImGui.pushId(imgui.kt:27)
at imgui.imgui.imgui_widgetsMain$DefaultImpls.imageButton(widgets main.kt:103)
at imgui.ImGui.imageButton(imgui.kt:27)
at imgui.imgui.imgui_widgetsMain$DefaultImpls.imageButton$default(widgets main.kt:96)
Why not use a dynamic list instead of a fixed array?
Thanks, Catvert.
Can you compile your own? If so, check my master branch. If that fixes it, i'll submit a PR
I just tried your master branch but the program crash with this stacktrace :
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:657)
at java.util.ArrayList.get(ArrayList.java:433)
at imgui.internal.Window.getId(classes.kt:560)
at imgui.imgui.imgui_window$DefaultImpls.begin(window.kt:435)
at imgui.ImGui.begin(imgui.kt:27)
at imgui.imgui.imgui_window$DefaultImpls.begin$default(window.kt:68)
at imgui.imgui.imgui_main$DefaultImpls.newFrame(main.kt:291)
at imgui.ImGui.newFrame(imgui.kt:27)
at imgui.impl.LwjglGL3.newFrame(LwjglGL3.kt:160)
#24 / my master branch has the fix
Seems not to work :( When I debug the following code :
fun getId(ptr: Any): Int {
val ptrIndex = ++ptrIndices
if(ptrIndex >= ptrId.size){
val newBufLength = ptrId.size + 512
val newBuf = Array(newBufLength, { java.lang.Byte(it.b) })
System.arraycopy(ptrId, 0, newBuf, 0, ptrId.size)
ptrId = newBuf
}
val id = System.identityHashCode(ptrId[++ptrIndices])
keepAliveId(id)
return id
}
The if is never true, so the array is never resized. Don't you miss a minus 1 after ptrId.size?
Thanks, Catvert.
The issue was the double ++ptrIndices, the code should now work as intended.
Nice it's working thanks ! :)