Allow "null" to be passed for string parameters.

NOTE: Not all native functions permit a null string to be passed, and may still fail. This change just fixes the null-ref that occurred wheen attempting to marshal the null string to UTF8.

Bumps beta identifier to beta3.
internals
Eric Mellino 6 years ago
parent 9212f835fa
commit 57de7ca047
  1. 12
      src/CodeGenerator/Program.cs
  2. 8
      src/ImGui.NET/Generated/GlyphRangesBuilder.gen.cs
  3. 48
      src/ImGui.NET/Generated/ImFontAtlas.gen.cs
  4. 3368
      src/ImGui.NET/Generated/ImGui.gen.cs
  5. 8
      src/ImGui.NET/Generated/ImGuiIO.gen.cs
  6. 8
      src/ImGui.NET/Generated/ImGuiInputTextCallbackData.gen.cs
  7. 8
      src/ImGui.NET/Generated/ImGuiPayload.gen.cs
  8. 8
      src/ImGui.NET/Generated/ImGuiTextBuffer.gen.cs
  9. 32
      src/ImGui.NET/Generated/ImGuiTextFilter.gen.cs
  10. 2
      src/ImGui.NET/ImGui.NET.csproj

@ -623,13 +623,19 @@ namespace CodeGenerator
}
else
{
preCallLines.Add($"int {correctedIdentifier}_byteCount = Encoding.UTF8.GetByteCount({textToEncode});");
preCallLines.Add($"byte* {nativeArgName} = stackalloc byte[{correctedIdentifier}_byteCount + 1];");
preCallLines.Add($"fixed (char* {correctedIdentifier}_ptr = {textToEncode})");
preCallLines.Add($"byte* {nativeArgName};");
preCallLines.Add($"if ({textToEncode} != null)");
preCallLines.Add("{");
preCallLines.Add($" int {correctedIdentifier}_byteCount = Encoding.UTF8.GetByteCount({textToEncode});");
preCallLines.Add($" byte* {nativeArgName}_stackBytes = stackalloc byte[{correctedIdentifier}_byteCount + 1];");
preCallLines.Add($" {nativeArgName} = {nativeArgName}_stackBytes;");
preCallLines.Add($" fixed (char* {correctedIdentifier}_ptr = {textToEncode})");
preCallLines.Add(" {");
preCallLines.Add($" int {nativeArgName}_offset = Encoding.UTF8.GetBytes({correctedIdentifier}_ptr, {textToEncode}.Length, {nativeArgName}, {correctedIdentifier}_byteCount);");
preCallLines.Add($" {nativeArgName}[{nativeArgName}_offset] = 0;");
preCallLines.Add(" }");
preCallLines.Add("}");
preCallLines.Add($"else {{ {nativeArgName} = null; }}");
}
}
else if (tr.Type == "char* []")

@ -23,14 +23,20 @@ namespace ImGuiNET
ImGuiNative.GlyphRangesBuilder_SetBit(NativePtr, n);
}
public void AddText(string text)
{
byte* native_text;
if (text != null)
{
int text_byteCount = Encoding.UTF8.GetByteCount(text);
byte* native_text = stackalloc byte[text_byteCount + 1];
byte* native_text_stackBytes = stackalloc byte[text_byteCount + 1];
native_text = native_text_stackBytes;
fixed (char* text_ptr = text)
{
int native_text_offset = Encoding.UTF8.GetBytes(text_ptr, text.Length, native_text, text_byteCount);
native_text[native_text_offset] = 0;
}
}
else { native_text = null; }
byte* native_text_end = null;
ImGuiNative.GlyphRangesBuilder_AddText(NativePtr, native_text, native_text_end);
}

@ -47,42 +47,60 @@ namespace ImGuiNET
public ImPtrVector<ImFontConfigPtr> ConfigData => new ImPtrVector<ImFontConfigPtr>(NativePtr->ConfigData, Unsafe.SizeOf<ImFontConfig>());
public RangeAccessor<int> CustomRectIds => new RangeAccessor<int>(NativePtr->CustomRectIds, 1);
public ImFontPtr AddFontFromMemoryCompressedBase85TTF(string compressed_font_data_base85, float size_pixels)
{
byte* native_compressed_font_data_base85;
if (compressed_font_data_base85 != null)
{
int compressed_font_data_base85_byteCount = Encoding.UTF8.GetByteCount(compressed_font_data_base85);
byte* native_compressed_font_data_base85 = stackalloc byte[compressed_font_data_base85_byteCount + 1];
byte* native_compressed_font_data_base85_stackBytes = stackalloc byte[compressed_font_data_base85_byteCount + 1];
native_compressed_font_data_base85 = native_compressed_font_data_base85_stackBytes;
fixed (char* compressed_font_data_base85_ptr = compressed_font_data_base85)
{
int native_compressed_font_data_base85_offset = Encoding.UTF8.GetBytes(compressed_font_data_base85_ptr, compressed_font_data_base85.Length, native_compressed_font_data_base85, compressed_font_data_base85_byteCount);
native_compressed_font_data_base85[native_compressed_font_data_base85_offset] = 0;
}
}
else { native_compressed_font_data_base85 = null; }
ImFontConfig* font_cfg = null;
ushort* glyph_ranges = null;
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(NativePtr, native_compressed_font_data_base85, size_pixels, font_cfg, glyph_ranges);
return new ImFontPtr(ret);
}
public ImFontPtr AddFontFromMemoryCompressedBase85TTF(string compressed_font_data_base85, float size_pixels, ImFontConfigPtr font_cfg)
{
byte* native_compressed_font_data_base85;
if (compressed_font_data_base85 != null)
{
int compressed_font_data_base85_byteCount = Encoding.UTF8.GetByteCount(compressed_font_data_base85);
byte* native_compressed_font_data_base85 = stackalloc byte[compressed_font_data_base85_byteCount + 1];
byte* native_compressed_font_data_base85_stackBytes = stackalloc byte[compressed_font_data_base85_byteCount + 1];
native_compressed_font_data_base85 = native_compressed_font_data_base85_stackBytes;
fixed (char* compressed_font_data_base85_ptr = compressed_font_data_base85)
{
int native_compressed_font_data_base85_offset = Encoding.UTF8.GetBytes(compressed_font_data_base85_ptr, compressed_font_data_base85.Length, native_compressed_font_data_base85, compressed_font_data_base85_byteCount);
native_compressed_font_data_base85[native_compressed_font_data_base85_offset] = 0;
}
}
else { native_compressed_font_data_base85 = null; }
ImFontConfig* native_font_cfg = font_cfg.NativePtr;
ushort* glyph_ranges = null;
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(NativePtr, native_compressed_font_data_base85, size_pixels, native_font_cfg, glyph_ranges);
return new ImFontPtr(ret);
}
public ImFontPtr AddFontFromMemoryCompressedBase85TTF(string compressed_font_data_base85, float size_pixels, ImFontConfigPtr font_cfg, IntPtr glyph_ranges)
{
byte* native_compressed_font_data_base85;
if (compressed_font_data_base85 != null)
{
int compressed_font_data_base85_byteCount = Encoding.UTF8.GetByteCount(compressed_font_data_base85);
byte* native_compressed_font_data_base85 = stackalloc byte[compressed_font_data_base85_byteCount + 1];
byte* native_compressed_font_data_base85_stackBytes = stackalloc byte[compressed_font_data_base85_byteCount + 1];
native_compressed_font_data_base85 = native_compressed_font_data_base85_stackBytes;
fixed (char* compressed_font_data_base85_ptr = compressed_font_data_base85)
{
int native_compressed_font_data_base85_offset = Encoding.UTF8.GetBytes(compressed_font_data_base85_ptr, compressed_font_data_base85.Length, native_compressed_font_data_base85, compressed_font_data_base85_byteCount);
native_compressed_font_data_base85[native_compressed_font_data_base85_offset] = 0;
}
}
else { native_compressed_font_data_base85 = null; }
ImFontConfig* native_font_cfg = font_cfg.NativePtr;
ushort* native_glyph_ranges = (ushort*)glyph_ranges.ToPointer();
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(NativePtr, native_compressed_font_data_base85, size_pixels, native_font_cfg, native_glyph_ranges);
@ -217,42 +235,60 @@ namespace ImGuiNET
return new ImFontPtr(ret);
}
public ImFontPtr AddFontFromFileTTF(string filename, float size_pixels)
{
byte* native_filename;
if (filename != null)
{
int filename_byteCount = Encoding.UTF8.GetByteCount(filename);
byte* native_filename = stackalloc byte[filename_byteCount + 1];
byte* native_filename_stackBytes = stackalloc byte[filename_byteCount + 1];
native_filename = native_filename_stackBytes;
fixed (char* filename_ptr = filename)
{
int native_filename_offset = Encoding.UTF8.GetBytes(filename_ptr, filename.Length, native_filename, filename_byteCount);
native_filename[native_filename_offset] = 0;
}
}
else { native_filename = null; }
ImFontConfig* font_cfg = null;
ushort* glyph_ranges = null;
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromFileTTF(NativePtr, native_filename, size_pixels, font_cfg, glyph_ranges);
return new ImFontPtr(ret);
}
public ImFontPtr AddFontFromFileTTF(string filename, float size_pixels, ImFontConfigPtr font_cfg)
{
byte* native_filename;
if (filename != null)
{
int filename_byteCount = Encoding.UTF8.GetByteCount(filename);
byte* native_filename = stackalloc byte[filename_byteCount + 1];
byte* native_filename_stackBytes = stackalloc byte[filename_byteCount + 1];
native_filename = native_filename_stackBytes;
fixed (char* filename_ptr = filename)
{
int native_filename_offset = Encoding.UTF8.GetBytes(filename_ptr, filename.Length, native_filename, filename_byteCount);
native_filename[native_filename_offset] = 0;
}
}
else { native_filename = null; }
ImFontConfig* native_font_cfg = font_cfg.NativePtr;
ushort* glyph_ranges = null;
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromFileTTF(NativePtr, native_filename, size_pixels, native_font_cfg, glyph_ranges);
return new ImFontPtr(ret);
}
public ImFontPtr AddFontFromFileTTF(string filename, float size_pixels, ImFontConfigPtr font_cfg, IntPtr glyph_ranges)
{
byte* native_filename;
if (filename != null)
{
int filename_byteCount = Encoding.UTF8.GetByteCount(filename);
byte* native_filename = stackalloc byte[filename_byteCount + 1];
byte* native_filename_stackBytes = stackalloc byte[filename_byteCount + 1];
native_filename = native_filename_stackBytes;
fixed (char* filename_ptr = filename)
{
int native_filename_offset = Encoding.UTF8.GetBytes(filename_ptr, filename.Length, native_filename, filename_byteCount);
native_filename[native_filename_offset] = 0;
}
}
else { native_filename = null; }
ImFontConfig* native_font_cfg = font_cfg.NativePtr;
ushort* native_glyph_ranges = (ushort*)glyph_ranges.ToPointer();
ImFont* ret = ImGuiNative.ImFontAtlas_AddFontFromFileTTF(NativePtr, native_filename, size_pixels, native_font_cfg, native_glyph_ranges);

File diff suppressed because it is too large Load Diff

@ -167,14 +167,20 @@ namespace ImGuiNET
public RangeAccessor<float> NavInputsDownDuration => new RangeAccessor<float>(NativePtr->NavInputsDownDuration, 21);
public RangeAccessor<float> NavInputsDownDurationPrev => new RangeAccessor<float>(NativePtr->NavInputsDownDurationPrev, 21);
public void AddInputCharactersUTF8(string utf8_chars)
{
byte* native_utf8_chars;
if (utf8_chars != null)
{
int utf8_chars_byteCount = Encoding.UTF8.GetByteCount(utf8_chars);
byte* native_utf8_chars = stackalloc byte[utf8_chars_byteCount + 1];
byte* native_utf8_chars_stackBytes = stackalloc byte[utf8_chars_byteCount + 1];
native_utf8_chars = native_utf8_chars_stackBytes;
fixed (char* utf8_chars_ptr = utf8_chars)
{
int native_utf8_chars_offset = Encoding.UTF8.GetBytes(utf8_chars_ptr, utf8_chars.Length, native_utf8_chars, utf8_chars_byteCount);
native_utf8_chars[native_utf8_chars_offset] = 0;
}
}
else { native_utf8_chars = null; }
ImGuiNative.ImGuiIO_AddInputCharactersUTF8(NativePtr, native_utf8_chars);
}
public void ClearInputCharacters()

@ -50,14 +50,20 @@ namespace ImGuiNET
return ret != 0;
}
public void InsertChars(int pos, string text)
{
byte* native_text;
if (text != null)
{
int text_byteCount = Encoding.UTF8.GetByteCount(text);
byte* native_text = stackalloc byte[text_byteCount + 1];
byte* native_text_stackBytes = stackalloc byte[text_byteCount + 1];
native_text = native_text_stackBytes;
fixed (char* text_ptr = text)
{
int native_text_offset = Encoding.UTF8.GetBytes(text_ptr, text.Length, native_text, text_byteCount);
native_text[native_text_offset] = 0;
}
}
else { native_text = null; }
byte* native_text_end = null;
ImGuiNative.ImGuiInputTextCallbackData_InsertChars(NativePtr, pos, native_text, native_text_end);
}

@ -42,14 +42,20 @@ namespace ImGuiNET
return ret != 0;
}
public bool IsDataType(string type)
{
byte* native_type;
if (type != null)
{
int type_byteCount = Encoding.UTF8.GetByteCount(type);
byte* native_type = stackalloc byte[type_byteCount + 1];
byte* native_type_stackBytes = stackalloc byte[type_byteCount + 1];
native_type = native_type_stackBytes;
fixed (char* type_ptr = type)
{
int native_type_offset = Encoding.UTF8.GetBytes(type_ptr, type.Length, native_type, type_byteCount);
native_type[native_type_offset] = 0;
}
}
else { native_type = null; }
byte ret = ImGuiNative.ImGuiPayload_IsDataType(NativePtr, native_type);
return ret != 0;
}

@ -23,14 +23,20 @@ namespace ImGuiNET
ImGuiNative.ImGuiTextBuffer_clear(NativePtr);
}
public void appendf(string fmt)
{
byte* native_fmt;
if (fmt != null)
{
int fmt_byteCount = Encoding.UTF8.GetByteCount(fmt);
byte* native_fmt = stackalloc byte[fmt_byteCount + 1];
byte* native_fmt_stackBytes = stackalloc byte[fmt_byteCount + 1];
native_fmt = native_fmt_stackBytes;
fixed (char* fmt_ptr = fmt)
{
int native_fmt_offset = Encoding.UTF8.GetBytes(fmt_ptr, fmt.Length, native_fmt, fmt_byteCount);
native_fmt[native_fmt_offset] = 0;
}
}
else { native_fmt = null; }
ImGuiNative.ImGuiTextBuffer_appendf(NativePtr, native_fmt);
}
public string c_str()

@ -27,40 +27,58 @@ namespace ImGuiNET
ImGuiNative.ImGuiTextFilter_Build(NativePtr);
}
public bool Draw()
{
byte* native_label;
if ("Filter(inc,-exc)" != null)
{
int label_byteCount = Encoding.UTF8.GetByteCount("Filter(inc,-exc)");
byte* native_label = stackalloc byte[label_byteCount + 1];
byte* native_label_stackBytes = stackalloc byte[label_byteCount + 1];
native_label = native_label_stackBytes;
fixed (char* label_ptr = "Filter(inc,-exc)")
{
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, "Filter(inc,-exc)".Length, native_label, label_byteCount);
native_label[native_label_offset] = 0;
}
}
else { native_label = null; }
float width = 0.0f;
byte ret = ImGuiNative.ImGuiTextFilter_Draw(NativePtr, native_label, width);
return ret != 0;
}
public bool Draw(string label)
{
byte* native_label;
if (label != null)
{
int label_byteCount = Encoding.UTF8.GetByteCount(label);
byte* native_label = stackalloc byte[label_byteCount + 1];
byte* native_label_stackBytes = stackalloc byte[label_byteCount + 1];
native_label = native_label_stackBytes;
fixed (char* label_ptr = label)
{
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount);
native_label[native_label_offset] = 0;
}
}
else { native_label = null; }
float width = 0.0f;
byte ret = ImGuiNative.ImGuiTextFilter_Draw(NativePtr, native_label, width);
return ret != 0;
}
public bool Draw(string label, float width)
{
byte* native_label;
if (label != null)
{
int label_byteCount = Encoding.UTF8.GetByteCount(label);
byte* native_label = stackalloc byte[label_byteCount + 1];
byte* native_label_stackBytes = stackalloc byte[label_byteCount + 1];
native_label = native_label_stackBytes;
fixed (char* label_ptr = label)
{
int native_label_offset = Encoding.UTF8.GetBytes(label_ptr, label.Length, native_label, label_byteCount);
native_label[native_label_offset] = 0;
}
}
else { native_label = null; }
byte ret = ImGuiNative.ImGuiTextFilter_Draw(NativePtr, native_label, width);
return ret != 0;
}
@ -74,14 +92,20 @@ namespace ImGuiNET
ImGuiNative.ImGuiTextFilter_Clear(NativePtr);
}
public bool PassFilter(string text)
{
byte* native_text;
if (text != null)
{
int text_byteCount = Encoding.UTF8.GetByteCount(text);
byte* native_text = stackalloc byte[text_byteCount + 1];
byte* native_text_stackBytes = stackalloc byte[text_byteCount + 1];
native_text = native_text_stackBytes;
fixed (char* text_ptr = text)
{
int native_text_offset = Encoding.UTF8.GetBytes(text_ptr, text.Length, native_text, text_byteCount);
native_text[native_text_offset] = 0;
}
}
else { native_text = null; }
byte* native_text_end = null;
byte ret = ImGuiNative.ImGuiTextFilter_PassFilter(NativePtr, native_text, native_text_end);
return ret != 0;

@ -8,7 +8,7 @@
<DebugType>portable</DebugType>
<AssemblyName>ImGui.NET</AssemblyName>
<PackageId>ImGui.NET</PackageId>
<PackagePrereleaseIdentifier>-beta2</PackagePrereleaseIdentifier>
<PackagePrereleaseIdentifier>-beta3</PackagePrereleaseIdentifier>
<PackageVersion>$(AssemblyVersion)$(PackagePrereleaseIdentifier)</PackageVersion>
<PackageTags>ImGui ImGui.NET Immediate Mode GUI</PackageTags>
<PackageProjectUrl>https://github.com/mellinoe/imgui.net</PackageProjectUrl>

Loading…
Cancel
Save