Skip to content

Bug: crash on tableGetSortSpecs #322

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

Open
phraktle opened this issue Feb 3, 2025 · 2 comments
Open

Bug: crash on tableGetSortSpecs #322

phraktle opened this issue Feb 3, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@phraktle
Copy link

phraktle commented Feb 3, 2025

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]

@phraktle phraktle added the bug Something isn't working label Feb 3, 2025
@SpaiR
Copy link
Owner

SpaiR commented Feb 4, 2025

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).

@phraktle
Copy link
Author

phraktle commented Feb 5, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants