ImGui.NET
ImGui.NET copied to clipboard
CodeGenerator parses size expressions incorrectly (wrong values and thrown exceptions)
The latest cimgui (master, hash be187bcdc43b124250f7c0f6b4c216a4094053b1) generates successfully, but CodeGenerator in ImGui.NET cannot process the output.
In structs_and_enums.json, under ImFont is the item:
{
"name": "Used4kPagesMap[(0xFFFF+1)/4096/8]",
"size": 2,
"type": "ImU8"
}
This fails to parse and throws here:
CodeGenerator.dll!CodeGenerator.TypeReference.ParseSizeString(string sizePart, CodeGenerator.EnumDefinition[] enums) Line 1182
CodeGenerator.dll!CodeGenerator.TypeReference.TypeReference(string name, string type, string templateType, CodeGenerator.EnumDefinition[] enums, string[] typeVariants) Line 1164
CodeGenerator.dll!CodeGenerator.TypeReference.TypeReference(string name, string type, string templateType, CodeGenerator.EnumDefinition[] enums) Line 1138
CodeGenerator.dll!CodeGenerator.Program.Main.AnonymousMethod__7(Newtonsoft.Json.Linq.JToken v) Line 173
I'll look at this a bit, but I am unfamiliar with cimgui's formatting or how CodeGenerator processes it, so I may not be able to address this correctly.
The actual definition in imgui is
ImU8 Used4kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/4096/8];
so I can see where that is coming from, though I'm not sure if is an ImGui.NET bug, or something that cimgui should be expected to resolve
Actually in quick debugging, other values parse incorrectly here as well, though they don't appear to throw.
"ArcFastVtx[12*1]"
evaluates its size to -1.
It seems like this needs more robust expression parsing.
I was able to hack around this to make the generator 'succeed', basically just using a regex to turn hex->decimal in the string and then using ncalc instead of the existing parse logic (ncalc seemingly cannot handle hex)
I also wasn't sure why it parses the size at all, since in cases where it is an expression, the result seems to be included in the json as a 'size' field, but I left this behavior in since I assumed there must be a reason for it.
However, there are a lot of other issues with the current cimgui that the generator just does not handle. I'll put those in a separate issue.
"ArcFastVtx[12*1]"
evaluates its size to -1.It seems like this needs more robust expression parsing.
This dont needs to be parsed, just take size field (and discard [xxx]
in name)
{
"name": "ArcFastVtx[12*1]",
"size": 12,
"type": "ImVec2"
},