Closed CodingMadness closed 1 year ago
Good idea, feel free to create PR
Good idea, feel free to create PR
I dont have time to work on that, would be nice if the owner or the actual collabs could work on this. I am nott familar with C
the owner or the actual collabs could work on this
unfortunately owner won't be able to commit to this repo (in the near future) due to some clause in their contract. As 1 of the collab, i just handle the release process of ImGui.net and is not familiar with C as well.
I think what I am trying to say over here is that the quickest route would be to contribute to this repo yourself. Otherwise, feel free to wait for some collab who knows C & is part of the project that uses ReadOnlySpan a lot.
@zaafar Can you direct me to atleast where would I need to do the changes, can this maybe be done only in his generated .cs files? or does it really have to be in C ?
Well, I am not expert in this but I will try my best to explain what I know.
it is a C# code (url: https://github.com/ImGuiNET/ImGui.NET/tree/master/src/CodeGenerator) that creates the .NET APIs
CodeGenerator inputs files (url: https://github.com/ImGuiNET/ImGui.NET/tree/master/src/CodeGenerator/definitions/cimgui) that comes from cimgui repo (url: https://github.com/cimgui/cimgui) and is in C format.
CodeGenerator outputs every file you see in the generated folder (url: https://github.com/ImGuiNET/ImGui.NET/tree/master/src/ImGui.NET/Generated) and is in C# format.
So what you are requesting would have to be changed in CodeGenerator project. You can start by figuring out (1) which function in the generated folder you wanna change (2) Which function in the input file it points to (3) which code in the CodeGenerator does that conversion.
I'm also interested in being able to use ReadOnlySpan<char>
instead of string
. However I think it's worth mentioning that ReadOnlySpan
is not supported on .NET Standard 2.0 (only 2.1), so I think we would need to generate overloads that accept ReadOnlySpan<char>
and wrap them in #if NETSTANDARD2_1_OR_GREATER
directives (correct me if I'm wrong here).
I might give it a try in the future.
@NoahStolk its a valuable effort i feel i currently am thinking to do the same but need to know where to start, zafaar did give a good insight in where to start but I did not yet come to the chance to begin it due to private endevors.
@NoahStolk @zaafar I think I have managed to do it!
Pls check out my repo: https://github.com/Shpendicus/ImGui.NET-master
I think sofar I have done it, I did rather quick so no deep testing, but when i checked roughly the .gen files, it seemed to accept my change!
Now this has only to be checked by the collabs and made a .nuget package.
can't see your repo.
can't see your repo.
can u check now?
please create a PR to this repo so i can see what changed.
yea sadly did not do that, will do tomorrow
@NoahStolk @zaafar I think I have managed to do it!
Pls check out my repo: https://github.com/Shpendicus/ImGui.NET-master
I think sofar I have done it, I did rather quick so no deep testing, but when i checked roughly the .gen files, it seemed to accept my change!
Nice! Just had a look at your changes. It's fairly difficult to see what exactly has changed with all the cleaning up and style modifications (I do think the generator needs cleaning up though -- but maybe it'd be better to do it separately without any functionality changes so we have a clear diff for this feature).
I also don't think it is desirable to drop .NET Standard 2.0 support, as the README states:
ImGui.NET is a .NET Standard library, and can be used on all major .NET runtimes and operating systems.
I think we'd have to figure out how to generate overloads for ReadOnlySpan<char>
and only include them if the target framework supports it.
@zaafar sadly due to some family accident, I have no time whatsoever to make a PR for this endevaor. I please you both to look at the changes (its not a lot, i will find the files and call them here for easier use ) and make a PR yourself!
Would be super good if this could make it into the current release
Also, @NoahStolk you guys would need to write then conditionals for that, regarding this quote here:
I think we'd have to figure out how to generate overloads for ReadOnlySpan
and only include them if the target framework supports it.
I have opened a PR with minimal changes to the code generator. It now generates overloads accepting ReadOnlySpan<char>
when targeting .NET Core 2.1+ / .NET Standard 2.1.
moving this and this discussion back to the original issue.
Apologies for missing that. Are you sure the IsEmpty check fixes it? Both null and string.Empty result in an AccessViolationException, even with IsEmpty. I'm not sure why yet.
yeah, null is working fine for me, it's just string.Empty that is resulting in Exception. I am basically compiling and running this project and exception is happening on this line.
What code are you running where null is also giving exception?
I have opened 2 more (draft) PRs to fix some issues:
https://github.com/ImGuiNET/ImGui.NET/pull/409 https://github.com/ImGuiNET/ImGui.NET/pull/410
moving this and this discussion back to the original issue.
Apologies for missing that. Are you sure the IsEmpty check fixes it? Both null and string.Empty result in an AccessViolationException, even with IsEmpty. I'm not sure why yet.
yeah, null is working fine for me, it's just string.Empty that is resulting in Exception. I am basically compiling and running this project and exception is happening on this line.
What code are you running where null is also giving exception?
@zaafar I added some test code to ImGui.NET.SampleProgram ( https://github.com/ImGuiNET/ImGui.NET/pull/410/files ). Both null and empty string crash for me on this branch.
This is using the Text
method.
FYI: I have just released 1.89.5.1 with all the changes you have done up till now. Lets try to fix the rest of the issues before I release 1.89.6.0 (which is blocked on https://github.com/cimgui/cimgui still on 1.89.5)
ImGui.Text(null)
also crashes on 1.89.5. Calling ImGuiNative.igText
with a null pointer in general just does not work.
Also, I found out that we can have all the ReadOnlySpan<char>
overloads without the preprocessor directives. The System.Memory
package provides the ReadOnlySpan
struct and is compatible with .NET Standard.
I will probably close the two drafts and open a new PR, which:
System.Memory
package instead of all those preprocessor directivesReadOnlySpan<char>
as wellI have opened a new PR which fixes all the current issues and closed the two drafts.
@zaafar FYI: I finished and re-opened my PR to apply ReadOnlySpan<char>
to ImGui.Manual.🙂
https://github.com/ImGuiNET/ImGui.NET/pull/409
Anything else that needs to be done before this issue can be closed?
That's the last thing.
Title.
Would be super nice if you could rewrite/adapt your C-parser of the ImGui files to accept ReadOnlySpan instead of string, cause this thing is used in Gameloop-code alot obviously and the amount of unnessecary garbage which will be created by "mySpan.ToString()" is enormous. Our code works heavily with spans to avoid tons of tons of allocations.
I hope you consider my writing here.
Best regards