From bc625f6b8417679c309c0f43e6e78c908e650eed Mon Sep 17 00:00:00 2001 From: Eric Mellino Date: Thu, 25 Oct 2018 21:06:23 -0700 Subject: [PATCH] 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. --- src/CodeGenerator/Program.cs | 16 ++++--- src/ImGui.NET/Generated/ImDrawData.gen.cs | 2 +- src/ImGui.NET/Generated/ImFont.gen.cs | 2 +- src/ImGui.NET/Generated/ImFontAtlas.gen.cs | 2 +- src/ImGui.NET/Generated/ImFontConfig.gen.cs | 6 +-- src/ImGui.NET/Generated/ImGuiIO.gen.cs | 44 +++++++++---------- .../ImGuiInputTextCallbackData.gen.cs | 2 +- src/ImGui.NET/Generated/ImGuiPayload.gen.cs | 4 +- src/ImGui.NET/Generated/ImGuiStyle.gen.cs | 4 +- 9 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/CodeGenerator/Program.cs b/src/CodeGenerator/Program.cs index 77a180d..7e2c088 100644 --- a/src/CodeGenerator/Program.cs +++ b/src/CodeGenerator/Program.cs @@ -54,7 +54,7 @@ namespace CodeGenerator private static readonly Dictionary s_wellKnownFieldReplacements = new Dictionary() { - { "bool", "Bool8" }, + { "bool", "bool" }, // Force bool to remain as bool in type-safe wrappers. }; private static readonly HashSet s_customDefinedTypes = new HashSet() @@ -159,11 +159,6 @@ namespace CodeGenerator { JProperty jp = (JProperty)jt; string name = jp.Name; - if (name.Contains("GetMousePos")) - { - - } - bool hasNonUdtVariants = jp.Values().Any(val => val["ov_cimguiname"]?.ToString().EndsWith("nonUDT") ?? false); OverloadDefinition[] overloads = jp.Values().Select(val => @@ -310,6 +305,15 @@ namespace CodeGenerator if (field.ArraySize != 0) { string addrTarget = s_legalFixedTypes.Contains(rawType) ? $"NativePtr->{field.Name}" : $"&NativePtr->{field.Name}_0"; + + if (field.Type == "bool") + { + // There appear to be codegen bugs on Unix when RangeAccessor is used which result + // in values beyond the accessed range becoming corrupted. + // Besides, bool is a better type to use in the first place. + typeStr = "bool"; + } + writer.WriteLine($"public RangeAccessor<{typeStr}> {field.Name} => new RangeAccessor<{typeStr}>({addrTarget}, {field.ArraySize});"); } else if (typeStr.Contains("ImVector")) diff --git a/src/ImGui.NET/Generated/ImDrawData.gen.cs b/src/ImGui.NET/Generated/ImDrawData.gen.cs index 79ed72f..94a9488 100644 --- a/src/ImGui.NET/Generated/ImDrawData.gen.cs +++ b/src/ImGui.NET/Generated/ImDrawData.gen.cs @@ -23,7 +23,7 @@ namespace ImGuiNET public static implicit operator ImDrawDataPtr(ImDrawData* nativePtr) => new ImDrawDataPtr(nativePtr); public static implicit operator ImDrawData* (ImDrawDataPtr wrappedPtr) => wrappedPtr.NativePtr; public static implicit operator ImDrawDataPtr(IntPtr nativePtr) => new ImDrawDataPtr(nativePtr); - public ref Bool8 Valid => ref Unsafe.AsRef(&NativePtr->Valid); + public ref bool Valid => ref Unsafe.AsRef(&NativePtr->Valid); public IntPtr CmdLists { get => (IntPtr)NativePtr->CmdLists; set => NativePtr->CmdLists = (ImDrawList**)value; } public ref int CmdListsCount => ref Unsafe.AsRef(&NativePtr->CmdListsCount); public ref int TotalIdxCount => ref Unsafe.AsRef(&NativePtr->TotalIdxCount); diff --git a/src/ImGui.NET/Generated/ImFont.gen.cs b/src/ImGui.NET/Generated/ImFont.gen.cs index fded502..6dbc365 100644 --- a/src/ImGui.NET/Generated/ImFont.gen.cs +++ b/src/ImGui.NET/Generated/ImFont.gen.cs @@ -46,7 +46,7 @@ namespace ImGuiNET public ImFontAtlasPtr ContainerAtlas => new ImFontAtlasPtr(NativePtr->ContainerAtlas); public ref float Ascent => ref Unsafe.AsRef(&NativePtr->Ascent); public ref float Descent => ref Unsafe.AsRef(&NativePtr->Descent); - public ref Bool8 DirtyLookupTables => ref Unsafe.AsRef(&NativePtr->DirtyLookupTables); + public ref bool DirtyLookupTables => ref Unsafe.AsRef(&NativePtr->DirtyLookupTables); public ref int MetricsTotalSurface => ref Unsafe.AsRef(&NativePtr->MetricsTotalSurface); public void AddRemapChar(ushort dst, ushort src) { diff --git a/src/ImGui.NET/Generated/ImFontAtlas.gen.cs b/src/ImGui.NET/Generated/ImFontAtlas.gen.cs index a187cc0..730650d 100644 --- a/src/ImGui.NET/Generated/ImFontAtlas.gen.cs +++ b/src/ImGui.NET/Generated/ImFontAtlas.gen.cs @@ -31,7 +31,7 @@ namespace ImGuiNET public static implicit operator ImFontAtlasPtr(ImFontAtlas* nativePtr) => new ImFontAtlasPtr(nativePtr); public static implicit operator ImFontAtlas* (ImFontAtlasPtr wrappedPtr) => wrappedPtr.NativePtr; public static implicit operator ImFontAtlasPtr(IntPtr nativePtr) => new ImFontAtlasPtr(nativePtr); - public ref Bool8 Locked => ref Unsafe.AsRef(&NativePtr->Locked); + public ref bool Locked => ref Unsafe.AsRef(&NativePtr->Locked); public ref ImFontAtlasFlags Flags => ref Unsafe.AsRef(&NativePtr->Flags); public ref IntPtr TexID => ref Unsafe.AsRef(&NativePtr->TexID); public ref int TexDesiredWidth => ref Unsafe.AsRef(&NativePtr->TexDesiredWidth); diff --git a/src/ImGui.NET/Generated/ImFontConfig.gen.cs b/src/ImGui.NET/Generated/ImFontConfig.gen.cs index f31b63a..9a55b82 100644 --- a/src/ImGui.NET/Generated/ImFontConfig.gen.cs +++ b/src/ImGui.NET/Generated/ImFontConfig.gen.cs @@ -36,18 +36,18 @@ namespace ImGuiNET public static implicit operator ImFontConfigPtr(IntPtr nativePtr) => new ImFontConfigPtr(nativePtr); public IntPtr FontData { get => (IntPtr)NativePtr->FontData; set => NativePtr->FontData = (void*)value; } public ref int FontDataSize => ref Unsafe.AsRef(&NativePtr->FontDataSize); - public ref Bool8 FontDataOwnedByAtlas => ref Unsafe.AsRef(&NativePtr->FontDataOwnedByAtlas); + public ref bool FontDataOwnedByAtlas => ref Unsafe.AsRef(&NativePtr->FontDataOwnedByAtlas); public ref int FontNo => ref Unsafe.AsRef(&NativePtr->FontNo); public ref float SizePixels => ref Unsafe.AsRef(&NativePtr->SizePixels); public ref int OversampleH => ref Unsafe.AsRef(&NativePtr->OversampleH); public ref int OversampleV => ref Unsafe.AsRef(&NativePtr->OversampleV); - public ref Bool8 PixelSnapH => ref Unsafe.AsRef(&NativePtr->PixelSnapH); + public ref bool PixelSnapH => ref Unsafe.AsRef(&NativePtr->PixelSnapH); public ref Vector2 GlyphExtraSpacing => ref Unsafe.AsRef(&NativePtr->GlyphExtraSpacing); public ref Vector2 GlyphOffset => ref Unsafe.AsRef(&NativePtr->GlyphOffset); public IntPtr GlyphRanges { get => (IntPtr)NativePtr->GlyphRanges; set => NativePtr->GlyphRanges = (ushort*)value; } public ref float GlyphMinAdvanceX => ref Unsafe.AsRef(&NativePtr->GlyphMinAdvanceX); public ref float GlyphMaxAdvanceX => ref Unsafe.AsRef(&NativePtr->GlyphMaxAdvanceX); - public ref Bool8 MergeMode => ref Unsafe.AsRef(&NativePtr->MergeMode); + public ref bool MergeMode => ref Unsafe.AsRef(&NativePtr->MergeMode); public ref uint RasterizerFlags => ref Unsafe.AsRef(&NativePtr->RasterizerFlags); public ref float RasterizerMultiply => ref Unsafe.AsRef(&NativePtr->RasterizerMultiply); public RangeAccessor Name => new RangeAccessor(NativePtr->Name, 40); diff --git a/src/ImGui.NET/Generated/ImGuiIO.gen.cs b/src/ImGui.NET/Generated/ImGuiIO.gen.cs index 489d033..070bf40 100644 --- a/src/ImGui.NET/Generated/ImGuiIO.gen.cs +++ b/src/ImGui.NET/Generated/ImGuiIO.gen.cs @@ -111,15 +111,15 @@ namespace ImGuiNET public IntPtr UserData { get => (IntPtr)NativePtr->UserData; set => NativePtr->UserData = (void*)value; } public ImFontAtlasPtr Fonts => new ImFontAtlasPtr(NativePtr->Fonts); public ref float FontGlobalScale => ref Unsafe.AsRef(&NativePtr->FontGlobalScale); - public ref Bool8 FontAllowUserScaling => ref Unsafe.AsRef(&NativePtr->FontAllowUserScaling); + public ref bool FontAllowUserScaling => ref Unsafe.AsRef(&NativePtr->FontAllowUserScaling); public ImFontPtr FontDefault => new ImFontPtr(NativePtr->FontDefault); public ref Vector2 DisplayFramebufferScale => ref Unsafe.AsRef(&NativePtr->DisplayFramebufferScale); public ref Vector2 DisplayVisibleMin => ref Unsafe.AsRef(&NativePtr->DisplayVisibleMin); public ref Vector2 DisplayVisibleMax => ref Unsafe.AsRef(&NativePtr->DisplayVisibleMax); - public ref Bool8 MouseDrawCursor => ref Unsafe.AsRef(&NativePtr->MouseDrawCursor); - public ref Bool8 ConfigMacOSXBehaviors => ref Unsafe.AsRef(&NativePtr->ConfigMacOSXBehaviors); - public ref Bool8 ConfigInputTextCursorBlink => ref Unsafe.AsRef(&NativePtr->ConfigInputTextCursorBlink); - public ref Bool8 ConfigResizeWindowsFromEdges => ref Unsafe.AsRef(&NativePtr->ConfigResizeWindowsFromEdges); + public ref bool MouseDrawCursor => ref Unsafe.AsRef(&NativePtr->MouseDrawCursor); + public ref bool ConfigMacOSXBehaviors => ref Unsafe.AsRef(&NativePtr->ConfigMacOSXBehaviors); + public ref bool ConfigInputTextCursorBlink => ref Unsafe.AsRef(&NativePtr->ConfigInputTextCursorBlink); + public ref bool ConfigResizeWindowsFromEdges => ref Unsafe.AsRef(&NativePtr->ConfigResizeWindowsFromEdges); public ref IntPtr GetClipboardTextFn => ref Unsafe.AsRef(&NativePtr->GetClipboardTextFn); public ref IntPtr SetClipboardTextFn => ref Unsafe.AsRef(&NativePtr->SetClipboardTextFn); public IntPtr ClipboardUserData { get => (IntPtr)NativePtr->ClipboardUserData; set => NativePtr->ClipboardUserData = (void*)value; } @@ -127,23 +127,23 @@ namespace ImGuiNET public IntPtr ImeWindowHandle { get => (IntPtr)NativePtr->ImeWindowHandle; set => NativePtr->ImeWindowHandle = (void*)value; } public IntPtr RenderDrawListsFnUnused { get => (IntPtr)NativePtr->RenderDrawListsFnUnused; set => NativePtr->RenderDrawListsFnUnused = (void*)value; } public ref Vector2 MousePos => ref Unsafe.AsRef(&NativePtr->MousePos); - public RangeAccessor MouseDown => new RangeAccessor(NativePtr->MouseDown, 5); + public RangeAccessor MouseDown => new RangeAccessor(NativePtr->MouseDown, 5); public ref float MouseWheel => ref Unsafe.AsRef(&NativePtr->MouseWheel); public ref float MouseWheelH => ref Unsafe.AsRef(&NativePtr->MouseWheelH); - public ref Bool8 KeyCtrl => ref Unsafe.AsRef(&NativePtr->KeyCtrl); - public ref Bool8 KeyShift => ref Unsafe.AsRef(&NativePtr->KeyShift); - public ref Bool8 KeyAlt => ref Unsafe.AsRef(&NativePtr->KeyAlt); - public ref Bool8 KeySuper => ref Unsafe.AsRef(&NativePtr->KeySuper); - public RangeAccessor KeysDown => new RangeAccessor(NativePtr->KeysDown, 512); + public ref bool KeyCtrl => ref Unsafe.AsRef(&NativePtr->KeyCtrl); + public ref bool KeyShift => ref Unsafe.AsRef(&NativePtr->KeyShift); + public ref bool KeyAlt => ref Unsafe.AsRef(&NativePtr->KeyAlt); + public ref bool KeySuper => ref Unsafe.AsRef(&NativePtr->KeySuper); + public RangeAccessor KeysDown => new RangeAccessor(NativePtr->KeysDown, 512); public RangeAccessor InputCharacters => new RangeAccessor(NativePtr->InputCharacters, 17); public RangeAccessor NavInputs => new RangeAccessor(NativePtr->NavInputs, 21); - public ref Bool8 WantCaptureMouse => ref Unsafe.AsRef(&NativePtr->WantCaptureMouse); - public ref Bool8 WantCaptureKeyboard => ref Unsafe.AsRef(&NativePtr->WantCaptureKeyboard); - public ref Bool8 WantTextInput => ref Unsafe.AsRef(&NativePtr->WantTextInput); - public ref Bool8 WantSetMousePos => ref Unsafe.AsRef(&NativePtr->WantSetMousePos); - public ref Bool8 WantSaveIniSettings => ref Unsafe.AsRef(&NativePtr->WantSaveIniSettings); - public ref Bool8 NavActive => ref Unsafe.AsRef(&NativePtr->NavActive); - public ref Bool8 NavVisible => ref Unsafe.AsRef(&NativePtr->NavVisible); + public ref bool WantCaptureMouse => ref Unsafe.AsRef(&NativePtr->WantCaptureMouse); + public ref bool WantCaptureKeyboard => ref Unsafe.AsRef(&NativePtr->WantCaptureKeyboard); + public ref bool WantTextInput => ref Unsafe.AsRef(&NativePtr->WantTextInput); + public ref bool WantSetMousePos => ref Unsafe.AsRef(&NativePtr->WantSetMousePos); + public ref bool WantSaveIniSettings => ref Unsafe.AsRef(&NativePtr->WantSaveIniSettings); + public ref bool NavActive => ref Unsafe.AsRef(&NativePtr->NavActive); + public ref bool NavVisible => ref Unsafe.AsRef(&NativePtr->NavVisible); public ref float Framerate => ref Unsafe.AsRef(&NativePtr->Framerate); public ref int MetricsRenderVertices => ref Unsafe.AsRef(&NativePtr->MetricsRenderVertices); public ref int MetricsRenderIndices => ref Unsafe.AsRef(&NativePtr->MetricsRenderIndices); @@ -154,10 +154,10 @@ namespace ImGuiNET public ref Vector2 MousePosPrev => ref Unsafe.AsRef(&NativePtr->MousePosPrev); public RangeAccessor MouseClickedPos => new RangeAccessor(&NativePtr->MouseClickedPos_0, 5); public RangeAccessor MouseClickedTime => new RangeAccessor(NativePtr->MouseClickedTime, 5); - public RangeAccessor MouseClicked => new RangeAccessor(NativePtr->MouseClicked, 5); - public RangeAccessor MouseDoubleClicked => new RangeAccessor(NativePtr->MouseDoubleClicked, 5); - public RangeAccessor MouseReleased => new RangeAccessor(NativePtr->MouseReleased, 5); - public RangeAccessor MouseDownOwned => new RangeAccessor(NativePtr->MouseDownOwned, 5); + public RangeAccessor MouseClicked => new RangeAccessor(NativePtr->MouseClicked, 5); + public RangeAccessor MouseDoubleClicked => new RangeAccessor(NativePtr->MouseDoubleClicked, 5); + public RangeAccessor MouseReleased => new RangeAccessor(NativePtr->MouseReleased, 5); + public RangeAccessor MouseDownOwned => new RangeAccessor(NativePtr->MouseDownOwned, 5); public RangeAccessor MouseDownDuration => new RangeAccessor(NativePtr->MouseDownDuration, 5); public RangeAccessor MouseDownDurationPrev => new RangeAccessor(NativePtr->MouseDownDurationPrev, 5); public RangeAccessor MouseDragMaxDistanceAbs => new RangeAccessor(&NativePtr->MouseDragMaxDistanceAbs_0, 5); diff --git a/src/ImGui.NET/Generated/ImGuiInputTextCallbackData.gen.cs b/src/ImGui.NET/Generated/ImGuiInputTextCallbackData.gen.cs index 5dc27f6..41cf236 100644 --- a/src/ImGui.NET/Generated/ImGuiInputTextCallbackData.gen.cs +++ b/src/ImGui.NET/Generated/ImGuiInputTextCallbackData.gen.cs @@ -36,7 +36,7 @@ namespace ImGuiNET public IntPtr Buf { get => (IntPtr)NativePtr->Buf; set => NativePtr->Buf = (byte*)value; } public ref int BufTextLen => ref Unsafe.AsRef(&NativePtr->BufTextLen); public ref int BufSize => ref Unsafe.AsRef(&NativePtr->BufSize); - public ref Bool8 BufDirty => ref Unsafe.AsRef(&NativePtr->BufDirty); + public ref bool BufDirty => ref Unsafe.AsRef(&NativePtr->BufDirty); public ref int CursorPos => ref Unsafe.AsRef(&NativePtr->CursorPos); public ref int SelectionStart => ref Unsafe.AsRef(&NativePtr->SelectionStart); public ref int SelectionEnd => ref Unsafe.AsRef(&NativePtr->SelectionEnd); diff --git a/src/ImGui.NET/Generated/ImGuiPayload.gen.cs b/src/ImGui.NET/Generated/ImGuiPayload.gen.cs index 7d05526..d06de1d 100644 --- a/src/ImGui.NET/Generated/ImGuiPayload.gen.cs +++ b/src/ImGui.NET/Generated/ImGuiPayload.gen.cs @@ -30,8 +30,8 @@ namespace ImGuiNET public ref uint SourceParentId => ref Unsafe.AsRef(&NativePtr->SourceParentId); public ref int DataFrameCount => ref Unsafe.AsRef(&NativePtr->DataFrameCount); public RangeAccessor DataType => new RangeAccessor(NativePtr->DataType, 33); - public ref Bool8 Preview => ref Unsafe.AsRef(&NativePtr->Preview); - public ref Bool8 Delivery => ref Unsafe.AsRef(&NativePtr->Delivery); + public ref bool Preview => ref Unsafe.AsRef(&NativePtr->Preview); + public ref bool Delivery => ref Unsafe.AsRef(&NativePtr->Delivery); public void Clear() { ImGuiNative.ImGuiPayload_Clear(NativePtr); diff --git a/src/ImGui.NET/Generated/ImGuiStyle.gen.cs b/src/ImGui.NET/Generated/ImGuiStyle.gen.cs index b754392..1881c7f 100644 --- a/src/ImGui.NET/Generated/ImGuiStyle.gen.cs +++ b/src/ImGui.NET/Generated/ImGuiStyle.gen.cs @@ -114,8 +114,8 @@ namespace ImGuiNET public ref Vector2 DisplayWindowPadding => ref Unsafe.AsRef(&NativePtr->DisplayWindowPadding); public ref Vector2 DisplaySafeAreaPadding => ref Unsafe.AsRef(&NativePtr->DisplaySafeAreaPadding); public ref float MouseCursorScale => ref Unsafe.AsRef(&NativePtr->MouseCursorScale); - public ref Bool8 AntiAliasedLines => ref Unsafe.AsRef(&NativePtr->AntiAliasedLines); - public ref Bool8 AntiAliasedFill => ref Unsafe.AsRef(&NativePtr->AntiAliasedFill); + public ref bool AntiAliasedLines => ref Unsafe.AsRef(&NativePtr->AntiAliasedLines); + public ref bool AntiAliasedFill => ref Unsafe.AsRef(&NativePtr->AntiAliasedFill); public ref float CurveTessellationTol => ref Unsafe.AsRef(&NativePtr->CurveTessellationTol); public RangeAccessor Colors => new RangeAccessor(&NativePtr->Colors_0, 43); public void ScaleAllSizes(float scale_factor)