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.
internals
Eric Mellino 6 years ago
parent 0a0774ff3c
commit bc625f6b84
  1. 16
      src/CodeGenerator/Program.cs
  2. 2
      src/ImGui.NET/Generated/ImDrawData.gen.cs
  3. 2
      src/ImGui.NET/Generated/ImFont.gen.cs
  4. 2
      src/ImGui.NET/Generated/ImFontAtlas.gen.cs
  5. 6
      src/ImGui.NET/Generated/ImFontConfig.gen.cs
  6. 44
      src/ImGui.NET/Generated/ImGuiIO.gen.cs
  7. 2
      src/ImGui.NET/Generated/ImGuiInputTextCallbackData.gen.cs
  8. 4
      src/ImGui.NET/Generated/ImGuiPayload.gen.cs
  9. 4
      src/ImGui.NET/Generated/ImGuiStyle.gen.cs

@ -54,7 +54,7 @@ namespace CodeGenerator
private static readonly Dictionary<string, string> s_wellKnownFieldReplacements = new Dictionary<string, string>()
{
{ "bool", "Bool8" },
{ "bool", "bool" }, // Force bool to remain as bool in type-safe wrappers.
};
private static readonly HashSet<string> s_customDefinedTypes = new HashSet<string>()
@ -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<Bool8> 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"))

@ -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<Bool8>(&NativePtr->Valid);
public ref bool Valid => ref Unsafe.AsRef<bool>(&NativePtr->Valid);
public IntPtr CmdLists { get => (IntPtr)NativePtr->CmdLists; set => NativePtr->CmdLists = (ImDrawList**)value; }
public ref int CmdListsCount => ref Unsafe.AsRef<int>(&NativePtr->CmdListsCount);
public ref int TotalIdxCount => ref Unsafe.AsRef<int>(&NativePtr->TotalIdxCount);

@ -46,7 +46,7 @@ namespace ImGuiNET
public ImFontAtlasPtr ContainerAtlas => new ImFontAtlasPtr(NativePtr->ContainerAtlas);
public ref float Ascent => ref Unsafe.AsRef<float>(&NativePtr->Ascent);
public ref float Descent => ref Unsafe.AsRef<float>(&NativePtr->Descent);
public ref Bool8 DirtyLookupTables => ref Unsafe.AsRef<Bool8>(&NativePtr->DirtyLookupTables);
public ref bool DirtyLookupTables => ref Unsafe.AsRef<bool>(&NativePtr->DirtyLookupTables);
public ref int MetricsTotalSurface => ref Unsafe.AsRef<int>(&NativePtr->MetricsTotalSurface);
public void AddRemapChar(ushort dst, ushort src)
{

@ -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<Bool8>(&NativePtr->Locked);
public ref bool Locked => ref Unsafe.AsRef<bool>(&NativePtr->Locked);
public ref ImFontAtlasFlags Flags => ref Unsafe.AsRef<ImFontAtlasFlags>(&NativePtr->Flags);
public ref IntPtr TexID => ref Unsafe.AsRef<IntPtr>(&NativePtr->TexID);
public ref int TexDesiredWidth => ref Unsafe.AsRef<int>(&NativePtr->TexDesiredWidth);

@ -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<int>(&NativePtr->FontDataSize);
public ref Bool8 FontDataOwnedByAtlas => ref Unsafe.AsRef<Bool8>(&NativePtr->FontDataOwnedByAtlas);
public ref bool FontDataOwnedByAtlas => ref Unsafe.AsRef<bool>(&NativePtr->FontDataOwnedByAtlas);
public ref int FontNo => ref Unsafe.AsRef<int>(&NativePtr->FontNo);
public ref float SizePixels => ref Unsafe.AsRef<float>(&NativePtr->SizePixels);
public ref int OversampleH => ref Unsafe.AsRef<int>(&NativePtr->OversampleH);
public ref int OversampleV => ref Unsafe.AsRef<int>(&NativePtr->OversampleV);
public ref Bool8 PixelSnapH => ref Unsafe.AsRef<Bool8>(&NativePtr->PixelSnapH);
public ref bool PixelSnapH => ref Unsafe.AsRef<bool>(&NativePtr->PixelSnapH);
public ref Vector2 GlyphExtraSpacing => ref Unsafe.AsRef<Vector2>(&NativePtr->GlyphExtraSpacing);
public ref Vector2 GlyphOffset => ref Unsafe.AsRef<Vector2>(&NativePtr->GlyphOffset);
public IntPtr GlyphRanges { get => (IntPtr)NativePtr->GlyphRanges; set => NativePtr->GlyphRanges = (ushort*)value; }
public ref float GlyphMinAdvanceX => ref Unsafe.AsRef<float>(&NativePtr->GlyphMinAdvanceX);
public ref float GlyphMaxAdvanceX => ref Unsafe.AsRef<float>(&NativePtr->GlyphMaxAdvanceX);
public ref Bool8 MergeMode => ref Unsafe.AsRef<Bool8>(&NativePtr->MergeMode);
public ref bool MergeMode => ref Unsafe.AsRef<bool>(&NativePtr->MergeMode);
public ref uint RasterizerFlags => ref Unsafe.AsRef<uint>(&NativePtr->RasterizerFlags);
public ref float RasterizerMultiply => ref Unsafe.AsRef<float>(&NativePtr->RasterizerMultiply);
public RangeAccessor<byte> Name => new RangeAccessor<byte>(NativePtr->Name, 40);

@ -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<float>(&NativePtr->FontGlobalScale);
public ref Bool8 FontAllowUserScaling => ref Unsafe.AsRef<Bool8>(&NativePtr->FontAllowUserScaling);
public ref bool FontAllowUserScaling => ref Unsafe.AsRef<bool>(&NativePtr->FontAllowUserScaling);
public ImFontPtr FontDefault => new ImFontPtr(NativePtr->FontDefault);
public ref Vector2 DisplayFramebufferScale => ref Unsafe.AsRef<Vector2>(&NativePtr->DisplayFramebufferScale);
public ref Vector2 DisplayVisibleMin => ref Unsafe.AsRef<Vector2>(&NativePtr->DisplayVisibleMin);
public ref Vector2 DisplayVisibleMax => ref Unsafe.AsRef<Vector2>(&NativePtr->DisplayVisibleMax);
public ref Bool8 MouseDrawCursor => ref Unsafe.AsRef<Bool8>(&NativePtr->MouseDrawCursor);
public ref Bool8 ConfigMacOSXBehaviors => ref Unsafe.AsRef<Bool8>(&NativePtr->ConfigMacOSXBehaviors);
public ref Bool8 ConfigInputTextCursorBlink => ref Unsafe.AsRef<Bool8>(&NativePtr->ConfigInputTextCursorBlink);
public ref Bool8 ConfigResizeWindowsFromEdges => ref Unsafe.AsRef<Bool8>(&NativePtr->ConfigResizeWindowsFromEdges);
public ref bool MouseDrawCursor => ref Unsafe.AsRef<bool>(&NativePtr->MouseDrawCursor);
public ref bool ConfigMacOSXBehaviors => ref Unsafe.AsRef<bool>(&NativePtr->ConfigMacOSXBehaviors);
public ref bool ConfigInputTextCursorBlink => ref Unsafe.AsRef<bool>(&NativePtr->ConfigInputTextCursorBlink);
public ref bool ConfigResizeWindowsFromEdges => ref Unsafe.AsRef<bool>(&NativePtr->ConfigResizeWindowsFromEdges);
public ref IntPtr GetClipboardTextFn => ref Unsafe.AsRef<IntPtr>(&NativePtr->GetClipboardTextFn);
public ref IntPtr SetClipboardTextFn => ref Unsafe.AsRef<IntPtr>(&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<Vector2>(&NativePtr->MousePos);
public RangeAccessor<Bool8> MouseDown => new RangeAccessor<Bool8>(NativePtr->MouseDown, 5);
public RangeAccessor<bool> MouseDown => new RangeAccessor<bool>(NativePtr->MouseDown, 5);
public ref float MouseWheel => ref Unsafe.AsRef<float>(&NativePtr->MouseWheel);
public ref float MouseWheelH => ref Unsafe.AsRef<float>(&NativePtr->MouseWheelH);
public ref Bool8 KeyCtrl => ref Unsafe.AsRef<Bool8>(&NativePtr->KeyCtrl);
public ref Bool8 KeyShift => ref Unsafe.AsRef<Bool8>(&NativePtr->KeyShift);
public ref Bool8 KeyAlt => ref Unsafe.AsRef<Bool8>(&NativePtr->KeyAlt);
public ref Bool8 KeySuper => ref Unsafe.AsRef<Bool8>(&NativePtr->KeySuper);
public RangeAccessor<Bool8> KeysDown => new RangeAccessor<Bool8>(NativePtr->KeysDown, 512);
public ref bool KeyCtrl => ref Unsafe.AsRef<bool>(&NativePtr->KeyCtrl);
public ref bool KeyShift => ref Unsafe.AsRef<bool>(&NativePtr->KeyShift);
public ref bool KeyAlt => ref Unsafe.AsRef<bool>(&NativePtr->KeyAlt);
public ref bool KeySuper => ref Unsafe.AsRef<bool>(&NativePtr->KeySuper);
public RangeAccessor<bool> KeysDown => new RangeAccessor<bool>(NativePtr->KeysDown, 512);
public RangeAccessor<ushort> InputCharacters => new RangeAccessor<ushort>(NativePtr->InputCharacters, 17);
public RangeAccessor<float> NavInputs => new RangeAccessor<float>(NativePtr->NavInputs, 21);
public ref Bool8 WantCaptureMouse => ref Unsafe.AsRef<Bool8>(&NativePtr->WantCaptureMouse);
public ref Bool8 WantCaptureKeyboard => ref Unsafe.AsRef<Bool8>(&NativePtr->WantCaptureKeyboard);
public ref Bool8 WantTextInput => ref Unsafe.AsRef<Bool8>(&NativePtr->WantTextInput);
public ref Bool8 WantSetMousePos => ref Unsafe.AsRef<Bool8>(&NativePtr->WantSetMousePos);
public ref Bool8 WantSaveIniSettings => ref Unsafe.AsRef<Bool8>(&NativePtr->WantSaveIniSettings);
public ref Bool8 NavActive => ref Unsafe.AsRef<Bool8>(&NativePtr->NavActive);
public ref Bool8 NavVisible => ref Unsafe.AsRef<Bool8>(&NativePtr->NavVisible);
public ref bool WantCaptureMouse => ref Unsafe.AsRef<bool>(&NativePtr->WantCaptureMouse);
public ref bool WantCaptureKeyboard => ref Unsafe.AsRef<bool>(&NativePtr->WantCaptureKeyboard);
public ref bool WantTextInput => ref Unsafe.AsRef<bool>(&NativePtr->WantTextInput);
public ref bool WantSetMousePos => ref Unsafe.AsRef<bool>(&NativePtr->WantSetMousePos);
public ref bool WantSaveIniSettings => ref Unsafe.AsRef<bool>(&NativePtr->WantSaveIniSettings);
public ref bool NavActive => ref Unsafe.AsRef<bool>(&NativePtr->NavActive);
public ref bool NavVisible => ref Unsafe.AsRef<bool>(&NativePtr->NavVisible);
public ref float Framerate => ref Unsafe.AsRef<float>(&NativePtr->Framerate);
public ref int MetricsRenderVertices => ref Unsafe.AsRef<int>(&NativePtr->MetricsRenderVertices);
public ref int MetricsRenderIndices => ref Unsafe.AsRef<int>(&NativePtr->MetricsRenderIndices);
@ -154,10 +154,10 @@ namespace ImGuiNET
public ref Vector2 MousePosPrev => ref Unsafe.AsRef<Vector2>(&NativePtr->MousePosPrev);
public RangeAccessor<Vector2> MouseClickedPos => new RangeAccessor<Vector2>(&NativePtr->MouseClickedPos_0, 5);
public RangeAccessor<double> MouseClickedTime => new RangeAccessor<double>(NativePtr->MouseClickedTime, 5);
public RangeAccessor<Bool8> MouseClicked => new RangeAccessor<Bool8>(NativePtr->MouseClicked, 5);
public RangeAccessor<Bool8> MouseDoubleClicked => new RangeAccessor<Bool8>(NativePtr->MouseDoubleClicked, 5);
public RangeAccessor<Bool8> MouseReleased => new RangeAccessor<Bool8>(NativePtr->MouseReleased, 5);
public RangeAccessor<Bool8> MouseDownOwned => new RangeAccessor<Bool8>(NativePtr->MouseDownOwned, 5);
public RangeAccessor<bool> MouseClicked => new RangeAccessor<bool>(NativePtr->MouseClicked, 5);
public RangeAccessor<bool> MouseDoubleClicked => new RangeAccessor<bool>(NativePtr->MouseDoubleClicked, 5);
public RangeAccessor<bool> MouseReleased => new RangeAccessor<bool>(NativePtr->MouseReleased, 5);
public RangeAccessor<bool> MouseDownOwned => new RangeAccessor<bool>(NativePtr->MouseDownOwned, 5);
public RangeAccessor<float> MouseDownDuration => new RangeAccessor<float>(NativePtr->MouseDownDuration, 5);
public RangeAccessor<float> MouseDownDurationPrev => new RangeAccessor<float>(NativePtr->MouseDownDurationPrev, 5);
public RangeAccessor<Vector2> MouseDragMaxDistanceAbs => new RangeAccessor<Vector2>(&NativePtr->MouseDragMaxDistanceAbs_0, 5);

@ -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<int>(&NativePtr->BufTextLen);
public ref int BufSize => ref Unsafe.AsRef<int>(&NativePtr->BufSize);
public ref Bool8 BufDirty => ref Unsafe.AsRef<Bool8>(&NativePtr->BufDirty);
public ref bool BufDirty => ref Unsafe.AsRef<bool>(&NativePtr->BufDirty);
public ref int CursorPos => ref Unsafe.AsRef<int>(&NativePtr->CursorPos);
public ref int SelectionStart => ref Unsafe.AsRef<int>(&NativePtr->SelectionStart);
public ref int SelectionEnd => ref Unsafe.AsRef<int>(&NativePtr->SelectionEnd);

@ -30,8 +30,8 @@ namespace ImGuiNET
public ref uint SourceParentId => ref Unsafe.AsRef<uint>(&NativePtr->SourceParentId);
public ref int DataFrameCount => ref Unsafe.AsRef<int>(&NativePtr->DataFrameCount);
public RangeAccessor<byte> DataType => new RangeAccessor<byte>(NativePtr->DataType, 33);
public ref Bool8 Preview => ref Unsafe.AsRef<Bool8>(&NativePtr->Preview);
public ref Bool8 Delivery => ref Unsafe.AsRef<Bool8>(&NativePtr->Delivery);
public ref bool Preview => ref Unsafe.AsRef<bool>(&NativePtr->Preview);
public ref bool Delivery => ref Unsafe.AsRef<bool>(&NativePtr->Delivery);
public void Clear()
{
ImGuiNative.ImGuiPayload_Clear(NativePtr);

@ -114,8 +114,8 @@ namespace ImGuiNET
public ref Vector2 DisplayWindowPadding => ref Unsafe.AsRef<Vector2>(&NativePtr->DisplayWindowPadding);
public ref Vector2 DisplaySafeAreaPadding => ref Unsafe.AsRef<Vector2>(&NativePtr->DisplaySafeAreaPadding);
public ref float MouseCursorScale => ref Unsafe.AsRef<float>(&NativePtr->MouseCursorScale);
public ref Bool8 AntiAliasedLines => ref Unsafe.AsRef<Bool8>(&NativePtr->AntiAliasedLines);
public ref Bool8 AntiAliasedFill => ref Unsafe.AsRef<Bool8>(&NativePtr->AntiAliasedFill);
public ref bool AntiAliasedLines => ref Unsafe.AsRef<bool>(&NativePtr->AntiAliasedLines);
public ref bool AntiAliasedFill => ref Unsafe.AsRef<bool>(&NativePtr->AntiAliasedFill);
public ref float CurveTessellationTol => ref Unsafe.AsRef<float>(&NativePtr->CurveTessellationTol);
public RangeAccessor<Vector4> Colors => new RangeAccessor<Vector4>(&NativePtr->Colors_0, 43);
public void ScaleAllSizes(float scale_factor)

Loading…
Cancel
Save