Skip to content

Commit bc625f6

Browse files
committed
In safe struct wrappers, do not use Bool8.
On .NET Core Unix platforms, there appears to be a codegen issue with Bool8 which causes it to mangle values after the accessed range. Conceptually, bool is the correc type to use in these places anyways, and because the marshaller is not involved here, there are no problems related to the marshaller's native-managed size mismatch.
1 parent 0a0774f commit bc625f6

9 files changed

Lines changed: 43 additions & 39 deletions

File tree

src/CodeGenerator/Program.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Program
5454

5555
private static readonly Dictionary<string, string> s_wellKnownFieldReplacements = new Dictionary<string, string>()
5656
{
57-
{ "bool", "Bool8" },
57+
{ "bool", "bool" }, // Force bool to remain as bool in type-safe wrappers.
5858
};
5959

6060
private static readonly HashSet<string> s_customDefinedTypes = new HashSet<string>()
@@ -159,11 +159,6 @@ static void Main(string[] args)
159159
{
160160
JProperty jp = (JProperty)jt;
161161
string name = jp.Name;
162-
if (name.Contains("GetMousePos"))
163-
{
164-
165-
}
166-
167162
bool hasNonUdtVariants = jp.Values().Any(val => val["ov_cimguiname"]?.ToString().EndsWith("nonUDT") ?? false);
168163

169164
OverloadDefinition[] overloads = jp.Values().Select(val =>
@@ -310,6 +305,15 @@ static void Main(string[] args)
310305
if (field.ArraySize != 0)
311306
{
312307
string addrTarget = s_legalFixedTypes.Contains(rawType) ? $"NativePtr->{field.Name}" : $"&NativePtr->{field.Name}_0";
308+
309+
if (field.Type == "bool")
310+
{
311+
// There appear to be codegen bugs on Unix when RangeAccessor<Bool8> is used which result
312+
// in values beyond the accessed range becoming corrupted.
313+
// Besides, bool is a better type to use in the first place.
314+
typeStr = "bool";
315+
}
316+
313317
writer.WriteLine($"public RangeAccessor<{typeStr}> {field.Name} => new RangeAccessor<{typeStr}>({addrTarget}, {field.ArraySize});");
314318
}
315319
else if (typeStr.Contains("ImVector"))

src/ImGui.NET/Generated/ImDrawData.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public unsafe partial struct ImDrawDataPtr
2323
public static implicit operator ImDrawDataPtr(ImDrawData* nativePtr) => new ImDrawDataPtr(nativePtr);
2424
public static implicit operator ImDrawData* (ImDrawDataPtr wrappedPtr) => wrappedPtr.NativePtr;
2525
public static implicit operator ImDrawDataPtr(IntPtr nativePtr) => new ImDrawDataPtr(nativePtr);
26-
public ref Bool8 Valid => ref Unsafe.AsRef<Bool8>(&NativePtr->Valid);
26+
public ref bool Valid => ref Unsafe.AsRef<bool>(&NativePtr->Valid);
2727
public IntPtr CmdLists { get => (IntPtr)NativePtr->CmdLists; set => NativePtr->CmdLists = (ImDrawList**)value; }
2828
public ref int CmdListsCount => ref Unsafe.AsRef<int>(&NativePtr->CmdListsCount);
2929
public ref int TotalIdxCount => ref Unsafe.AsRef<int>(&NativePtr->TotalIdxCount);

src/ImGui.NET/Generated/ImFont.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public unsafe partial struct ImFontPtr
4646
public ImFontAtlasPtr ContainerAtlas => new ImFontAtlasPtr(NativePtr->ContainerAtlas);
4747
public ref float Ascent => ref Unsafe.AsRef<float>(&NativePtr->Ascent);
4848
public ref float Descent => ref Unsafe.AsRef<float>(&NativePtr->Descent);
49-
public ref Bool8 DirtyLookupTables => ref Unsafe.AsRef<Bool8>(&NativePtr->DirtyLookupTables);
49+
public ref bool DirtyLookupTables => ref Unsafe.AsRef<bool>(&NativePtr->DirtyLookupTables);
5050
public ref int MetricsTotalSurface => ref Unsafe.AsRef<int>(&NativePtr->MetricsTotalSurface);
5151
public void AddRemapChar(ushort dst, ushort src)
5252
{

src/ImGui.NET/Generated/ImFontAtlas.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public unsafe partial struct ImFontAtlasPtr
3131
public static implicit operator ImFontAtlasPtr(ImFontAtlas* nativePtr) => new ImFontAtlasPtr(nativePtr);
3232
public static implicit operator ImFontAtlas* (ImFontAtlasPtr wrappedPtr) => wrappedPtr.NativePtr;
3333
public static implicit operator ImFontAtlasPtr(IntPtr nativePtr) => new ImFontAtlasPtr(nativePtr);
34-
public ref Bool8 Locked => ref Unsafe.AsRef<Bool8>(&NativePtr->Locked);
34+
public ref bool Locked => ref Unsafe.AsRef<bool>(&NativePtr->Locked);
3535
public ref ImFontAtlasFlags Flags => ref Unsafe.AsRef<ImFontAtlasFlags>(&NativePtr->Flags);
3636
public ref IntPtr TexID => ref Unsafe.AsRef<IntPtr>(&NativePtr->TexID);
3737
public ref int TexDesiredWidth => ref Unsafe.AsRef<int>(&NativePtr->TexDesiredWidth);

src/ImGui.NET/Generated/ImFontConfig.gen.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ public unsafe partial struct ImFontConfigPtr
3636
public static implicit operator ImFontConfigPtr(IntPtr nativePtr) => new ImFontConfigPtr(nativePtr);
3737
public IntPtr FontData { get => (IntPtr)NativePtr->FontData; set => NativePtr->FontData = (void*)value; }
3838
public ref int FontDataSize => ref Unsafe.AsRef<int>(&NativePtr->FontDataSize);
39-
public ref Bool8 FontDataOwnedByAtlas => ref Unsafe.AsRef<Bool8>(&NativePtr->FontDataOwnedByAtlas);
39+
public ref bool FontDataOwnedByAtlas => ref Unsafe.AsRef<bool>(&NativePtr->FontDataOwnedByAtlas);
4040
public ref int FontNo => ref Unsafe.AsRef<int>(&NativePtr->FontNo);
4141
public ref float SizePixels => ref Unsafe.AsRef<float>(&NativePtr->SizePixels);
4242
public ref int OversampleH => ref Unsafe.AsRef<int>(&NativePtr->OversampleH);
4343
public ref int OversampleV => ref Unsafe.AsRef<int>(&NativePtr->OversampleV);
44-
public ref Bool8 PixelSnapH => ref Unsafe.AsRef<Bool8>(&NativePtr->PixelSnapH);
44+
public ref bool PixelSnapH => ref Unsafe.AsRef<bool>(&NativePtr->PixelSnapH);
4545
public ref Vector2 GlyphExtraSpacing => ref Unsafe.AsRef<Vector2>(&NativePtr->GlyphExtraSpacing);
4646
public ref Vector2 GlyphOffset => ref Unsafe.AsRef<Vector2>(&NativePtr->GlyphOffset);
4747
public IntPtr GlyphRanges { get => (IntPtr)NativePtr->GlyphRanges; set => NativePtr->GlyphRanges = (ushort*)value; }
4848
public ref float GlyphMinAdvanceX => ref Unsafe.AsRef<float>(&NativePtr->GlyphMinAdvanceX);
4949
public ref float GlyphMaxAdvanceX => ref Unsafe.AsRef<float>(&NativePtr->GlyphMaxAdvanceX);
50-
public ref Bool8 MergeMode => ref Unsafe.AsRef<Bool8>(&NativePtr->MergeMode);
50+
public ref bool MergeMode => ref Unsafe.AsRef<bool>(&NativePtr->MergeMode);
5151
public ref uint RasterizerFlags => ref Unsafe.AsRef<uint>(&NativePtr->RasterizerFlags);
5252
public ref float RasterizerMultiply => ref Unsafe.AsRef<float>(&NativePtr->RasterizerMultiply);
5353
public RangeAccessor<byte> Name => new RangeAccessor<byte>(NativePtr->Name, 40);

src/ImGui.NET/Generated/ImGuiIO.gen.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,39 +111,39 @@ public unsafe partial struct ImGuiIOPtr
111111
public IntPtr UserData { get => (IntPtr)NativePtr->UserData; set => NativePtr->UserData = (void*)value; }
112112
public ImFontAtlasPtr Fonts => new ImFontAtlasPtr(NativePtr->Fonts);
113113
public ref float FontGlobalScale => ref Unsafe.AsRef<float>(&NativePtr->FontGlobalScale);
114-
public ref Bool8 FontAllowUserScaling => ref Unsafe.AsRef<Bool8>(&NativePtr->FontAllowUserScaling);
114+
public ref bool FontAllowUserScaling => ref Unsafe.AsRef<bool>(&NativePtr->FontAllowUserScaling);
115115
public ImFontPtr FontDefault => new ImFontPtr(NativePtr->FontDefault);
116116
public ref Vector2 DisplayFramebufferScale => ref Unsafe.AsRef<Vector2>(&NativePtr->DisplayFramebufferScale);
117117
public ref Vector2 DisplayVisibleMin => ref Unsafe.AsRef<Vector2>(&NativePtr->DisplayVisibleMin);
118118
public ref Vector2 DisplayVisibleMax => ref Unsafe.AsRef<Vector2>(&NativePtr->DisplayVisibleMax);
119-
public ref Bool8 MouseDrawCursor => ref Unsafe.AsRef<Bool8>(&NativePtr->MouseDrawCursor);
120-
public ref Bool8 ConfigMacOSXBehaviors => ref Unsafe.AsRef<Bool8>(&NativePtr->ConfigMacOSXBehaviors);
121-
public ref Bool8 ConfigInputTextCursorBlink => ref Unsafe.AsRef<Bool8>(&NativePtr->ConfigInputTextCursorBlink);
122-
public ref Bool8 ConfigResizeWindowsFromEdges => ref Unsafe.AsRef<Bool8>(&NativePtr->ConfigResizeWindowsFromEdges);
119+
public ref bool MouseDrawCursor => ref Unsafe.AsRef<bool>(&NativePtr->MouseDrawCursor);
120+
public ref bool ConfigMacOSXBehaviors => ref Unsafe.AsRef<bool>(&NativePtr->ConfigMacOSXBehaviors);
121+
public ref bool ConfigInputTextCursorBlink => ref Unsafe.AsRef<bool>(&NativePtr->ConfigInputTextCursorBlink);
122+
public ref bool ConfigResizeWindowsFromEdges => ref Unsafe.AsRef<bool>(&NativePtr->ConfigResizeWindowsFromEdges);
123123
public ref IntPtr GetClipboardTextFn => ref Unsafe.AsRef<IntPtr>(&NativePtr->GetClipboardTextFn);
124124
public ref IntPtr SetClipboardTextFn => ref Unsafe.AsRef<IntPtr>(&NativePtr->SetClipboardTextFn);
125125
public IntPtr ClipboardUserData { get => (IntPtr)NativePtr->ClipboardUserData; set => NativePtr->ClipboardUserData = (void*)value; }
126126
public ref IntPtr ImeSetInputScreenPosFn => ref Unsafe.AsRef<IntPtr>(&NativePtr->ImeSetInputScreenPosFn);
127127
public IntPtr ImeWindowHandle { get => (IntPtr)NativePtr->ImeWindowHandle; set => NativePtr->ImeWindowHandle = (void*)value; }
128128
public IntPtr RenderDrawListsFnUnused { get => (IntPtr)NativePtr->RenderDrawListsFnUnused; set => NativePtr->RenderDrawListsFnUnused = (void*)value; }
129129
public ref Vector2 MousePos => ref Unsafe.AsRef<Vector2>(&NativePtr->MousePos);
130-
public RangeAccessor<Bool8> MouseDown => new RangeAccessor<Bool8>(NativePtr->MouseDown, 5);
130+
public RangeAccessor<bool> MouseDown => new RangeAccessor<bool>(NativePtr->MouseDown, 5);
131131
public ref float MouseWheel => ref Unsafe.AsRef<float>(&NativePtr->MouseWheel);
132132
public ref float MouseWheelH => ref Unsafe.AsRef<float>(&NativePtr->MouseWheelH);
133-
public ref Bool8 KeyCtrl => ref Unsafe.AsRef<Bool8>(&NativePtr->KeyCtrl);
134-
public ref Bool8 KeyShift => ref Unsafe.AsRef<Bool8>(&NativePtr->KeyShift);
135-
public ref Bool8 KeyAlt => ref Unsafe.AsRef<Bool8>(&NativePtr->KeyAlt);
136-
public ref Bool8 KeySuper => ref Unsafe.AsRef<Bool8>(&NativePtr->KeySuper);
137-
public RangeAccessor<Bool8> KeysDown => new RangeAccessor<Bool8>(NativePtr->KeysDown, 512);
133+
public ref bool KeyCtrl => ref Unsafe.AsRef<bool>(&NativePtr->KeyCtrl);
134+
public ref bool KeyShift => ref Unsafe.AsRef<bool>(&NativePtr->KeyShift);
135+
public ref bool KeyAlt => ref Unsafe.AsRef<bool>(&NativePtr->KeyAlt);
136+
public ref bool KeySuper => ref Unsafe.AsRef<bool>(&NativePtr->KeySuper);
137+
public RangeAccessor<bool> KeysDown => new RangeAccessor<bool>(NativePtr->KeysDown, 512);
138138
public RangeAccessor<ushort> InputCharacters => new RangeAccessor<ushort>(NativePtr->InputCharacters, 17);
139139
public RangeAccessor<float> NavInputs => new RangeAccessor<float>(NativePtr->NavInputs, 21);
140-
public ref Bool8 WantCaptureMouse => ref Unsafe.AsRef<Bool8>(&NativePtr->WantCaptureMouse);
141-
public ref Bool8 WantCaptureKeyboard => ref Unsafe.AsRef<Bool8>(&NativePtr->WantCaptureKeyboard);
142-
public ref Bool8 WantTextInput => ref Unsafe.AsRef<Bool8>(&NativePtr->WantTextInput);
143-
public ref Bool8 WantSetMousePos => ref Unsafe.AsRef<Bool8>(&NativePtr->WantSetMousePos);
144-
public ref Bool8 WantSaveIniSettings => ref Unsafe.AsRef<Bool8>(&NativePtr->WantSaveIniSettings);
145-
public ref Bool8 NavActive => ref Unsafe.AsRef<Bool8>(&NativePtr->NavActive);
146-
public ref Bool8 NavVisible => ref Unsafe.AsRef<Bool8>(&NativePtr->NavVisible);
140+
public ref bool WantCaptureMouse => ref Unsafe.AsRef<bool>(&NativePtr->WantCaptureMouse);
141+
public ref bool WantCaptureKeyboard => ref Unsafe.AsRef<bool>(&NativePtr->WantCaptureKeyboard);
142+
public ref bool WantTextInput => ref Unsafe.AsRef<bool>(&NativePtr->WantTextInput);
143+
public ref bool WantSetMousePos => ref Unsafe.AsRef<bool>(&NativePtr->WantSetMousePos);
144+
public ref bool WantSaveIniSettings => ref Unsafe.AsRef<bool>(&NativePtr->WantSaveIniSettings);
145+
public ref bool NavActive => ref Unsafe.AsRef<bool>(&NativePtr->NavActive);
146+
public ref bool NavVisible => ref Unsafe.AsRef<bool>(&NativePtr->NavVisible);
147147
public ref float Framerate => ref Unsafe.AsRef<float>(&NativePtr->Framerate);
148148
public ref int MetricsRenderVertices => ref Unsafe.AsRef<int>(&NativePtr->MetricsRenderVertices);
149149
public ref int MetricsRenderIndices => ref Unsafe.AsRef<int>(&NativePtr->MetricsRenderIndices);
@@ -154,10 +154,10 @@ public unsafe partial struct ImGuiIOPtr
154154
public ref Vector2 MousePosPrev => ref Unsafe.AsRef<Vector2>(&NativePtr->MousePosPrev);
155155
public RangeAccessor<Vector2> MouseClickedPos => new RangeAccessor<Vector2>(&NativePtr->MouseClickedPos_0, 5);
156156
public RangeAccessor<double> MouseClickedTime => new RangeAccessor<double>(NativePtr->MouseClickedTime, 5);
157-
public RangeAccessor<Bool8> MouseClicked => new RangeAccessor<Bool8>(NativePtr->MouseClicked, 5);
158-
public RangeAccessor<Bool8> MouseDoubleClicked => new RangeAccessor<Bool8>(NativePtr->MouseDoubleClicked, 5);
159-
public RangeAccessor<Bool8> MouseReleased => new RangeAccessor<Bool8>(NativePtr->MouseReleased, 5);
160-
public RangeAccessor<Bool8> MouseDownOwned => new RangeAccessor<Bool8>(NativePtr->MouseDownOwned, 5);
157+
public RangeAccessor<bool> MouseClicked => new RangeAccessor<bool>(NativePtr->MouseClicked, 5);
158+
public RangeAccessor<bool> MouseDoubleClicked => new RangeAccessor<bool>(NativePtr->MouseDoubleClicked, 5);
159+
public RangeAccessor<bool> MouseReleased => new RangeAccessor<bool>(NativePtr->MouseReleased, 5);
160+
public RangeAccessor<bool> MouseDownOwned => new RangeAccessor<bool>(NativePtr->MouseDownOwned, 5);
161161
public RangeAccessor<float> MouseDownDuration => new RangeAccessor<float>(NativePtr->MouseDownDuration, 5);
162162
public RangeAccessor<float> MouseDownDurationPrev => new RangeAccessor<float>(NativePtr->MouseDownDurationPrev, 5);
163163
public RangeAccessor<Vector2> MouseDragMaxDistanceAbs => new RangeAccessor<Vector2>(&NativePtr->MouseDragMaxDistanceAbs_0, 5);

src/ImGui.NET/Generated/ImGuiInputTextCallbackData.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public unsafe partial struct ImGuiInputTextCallbackDataPtr
3636
public IntPtr Buf { get => (IntPtr)NativePtr->Buf; set => NativePtr->Buf = (byte*)value; }
3737
public ref int BufTextLen => ref Unsafe.AsRef<int>(&NativePtr->BufTextLen);
3838
public ref int BufSize => ref Unsafe.AsRef<int>(&NativePtr->BufSize);
39-
public ref Bool8 BufDirty => ref Unsafe.AsRef<Bool8>(&NativePtr->BufDirty);
39+
public ref bool BufDirty => ref Unsafe.AsRef<bool>(&NativePtr->BufDirty);
4040
public ref int CursorPos => ref Unsafe.AsRef<int>(&NativePtr->CursorPos);
4141
public ref int SelectionStart => ref Unsafe.AsRef<int>(&NativePtr->SelectionStart);
4242
public ref int SelectionEnd => ref Unsafe.AsRef<int>(&NativePtr->SelectionEnd);

src/ImGui.NET/Generated/ImGuiPayload.gen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public unsafe partial struct ImGuiPayloadPtr
3030
public ref uint SourceParentId => ref Unsafe.AsRef<uint>(&NativePtr->SourceParentId);
3131
public ref int DataFrameCount => ref Unsafe.AsRef<int>(&NativePtr->DataFrameCount);
3232
public RangeAccessor<byte> DataType => new RangeAccessor<byte>(NativePtr->DataType, 33);
33-
public ref Bool8 Preview => ref Unsafe.AsRef<Bool8>(&NativePtr->Preview);
34-
public ref Bool8 Delivery => ref Unsafe.AsRef<Bool8>(&NativePtr->Delivery);
33+
public ref bool Preview => ref Unsafe.AsRef<bool>(&NativePtr->Preview);
34+
public ref bool Delivery => ref Unsafe.AsRef<bool>(&NativePtr->Delivery);
3535
public void Clear()
3636
{
3737
ImGuiNative.ImGuiPayload_Clear(NativePtr);

src/ImGui.NET/Generated/ImGuiStyle.gen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public unsafe partial struct ImGuiStylePtr
114114
public ref Vector2 DisplayWindowPadding => ref Unsafe.AsRef<Vector2>(&NativePtr->DisplayWindowPadding);
115115
public ref Vector2 DisplaySafeAreaPadding => ref Unsafe.AsRef<Vector2>(&NativePtr->DisplaySafeAreaPadding);
116116
public ref float MouseCursorScale => ref Unsafe.AsRef<float>(&NativePtr->MouseCursorScale);
117-
public ref Bool8 AntiAliasedLines => ref Unsafe.AsRef<Bool8>(&NativePtr->AntiAliasedLines);
118-
public ref Bool8 AntiAliasedFill => ref Unsafe.AsRef<Bool8>(&NativePtr->AntiAliasedFill);
117+
public ref bool AntiAliasedLines => ref Unsafe.AsRef<bool>(&NativePtr->AntiAliasedLines);
118+
public ref bool AntiAliasedFill => ref Unsafe.AsRef<bool>(&NativePtr->AntiAliasedFill);
119119
public ref float CurveTessellationTol => ref Unsafe.AsRef<float>(&NativePtr->CurveTessellationTol);
120120
public RangeAccessor<Vector4> Colors => new RangeAccessor<Vector4>(&NativePtr->Colors_0, 43);
121121
public void ScaleAllSizes(float scale_factor)

0 commit comments

Comments
 (0)