Bug: crash on tableGetSortSpecs
Version
1.89.0
What happened?
When the table is not sortable, calling tableGetSortSpecs results in a crash, rather than returning null as documented (there is a simple workaround of checking if its sortable, so not a high priority problem)
/**
* Get latest sort specs for the table (NULL if not sorting).
* Lifetime: don't hold on this pointer over multiple frames or past any subsequent call to BeginTable().
*/
public static ImGuiTableSortSpecs tableGetSortSpecs() {
return new ImGuiTableSortSpecs(nTableGetSortSpecs());
}
Reproduction
call tableGetSortSpecs on a table without setting the Sortable flag
Relevant log output
Current thread (0x0000000137828c00): JavaThread "main" [_thread_in_native, id=259, stack(0x000000016f474000,0x000000016fc70000) (8176K)]
Stack: [0x000000016f474000,0x000000016fc70000], sp=0x000000016fc6bed0, free space=8159k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libimgui-java64.dylib+0xa0398] Java_imgui_ImGuiTableSortSpecs_nGetSpecs+0x48
J 4954 imgui.ImGuiTableSortSpecs.nGetSpecs()[J (0 bytes) @ 0x0000000117073064 [0x0000000117072fc0+0x00000000000000a4]
J 7597 c2 imgui.ImGuiTableSortSpecs.getSpecs()[Limgui/ImGuiTableColumnSortSpecs; (40 bytes) @ 0x000000011725600c [0x0000000117255fc0+0x000000000000004c]
Yes, the issue does exist, but a valid approach in this situation would be to check if (tableGetSortSpecs().isValidPtr()). In the way how it works isValidPtr() is equivalent to if (tableGetSortSpecs() != null).
I guess this is a more general stylistic question, whether the imgui-java APIs return nulls or non-nulls with isValidPtr false. Perhaps null would be safer as a policy (NPE rather than JVM crash on dereferencing). But I'm okay with closing this specific ticket.