Skip to content

Allow passing Unsafe.NullRef<bool>() for nullable bool* parameters - #535

Open
armadavalor wants to merge 1 commit into
ImGuiNET:masterfrom
armadavalor:fix-null-ref-bool-pointer
Open

armadavalor wants to merge 1 commit into
ImGuiNET:masterfrom
armadavalor:fix-null-ref-bool-pointer

Conversation

@armadavalor

Copy link
Copy Markdown

Generated wrappers that take a ref bool for a native bool* (such as p_open in BeginTabItem, Begin, CollapsingHeader, BeginPopupModal) always dereference the ref. Passing ref Unsafe.NullRef<bool>() either crashes with a NullReferenceException or never hands a null pointer to cimgui, so there is no way to get the native "no close button" behaviour through the ref bool overloads.

This change makes the code generator check Unsafe.IsNullRef first. If the ref is null, null is passed to the native function and nothing is written back. Otherwise the behaviour is the same as before. The ref is only read inside the branch; with the value folded into a single && expression, the JIT could still load it unconditionally and fault.

The generated files for ImGui.NET, ImPlot.NET and ImNodes.NET are regenerated with the updated generator. ImGuizmo has no bool* parameters and is unchanged. Only the bool* marshalling blocks change; the rest of the regenerated output was left as it is in master.

Tested on win-x64 with the bundled cimgui (Debug and Release): BeginTabItem("a", ref Unsafe.NullRef<bool>(), ...) now shows the tab, ref false still hides it, and ref true stays true.

Closes #495

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BeginTabItem's parameter p_open cannot be null reference

1 participant