Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: ImGuiInputTextCallbackData#insertChars handles UTF-8 characters incorrectly #207

Open
phoenix-the-uncreative opened this issue Oct 29, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@phoenix-the-uncreative
Copy link

Version

1.86.11

What happened?

ImGuiInputTextCallbackData#insertChars works fine when inserting ASCII characters, but inserts wrong characters when trying to add anything else.

Reproduction

When setting the buffer returned by an InputText callback like so:

String newText = "new text";
data.setBufDirty(true);
data.deleteChars(0, data.getBuf().length());
data.insertChars(0, newText);

It works perfectly when using only ASCII characters. However, if you use UTF-8 characters (for example, Cyrillic), the buffer is also fed with some incorrect bytes.

For example, here's how the buffer looks before writing in Russian:

"hello"

And here's how it looks after typing "я":

"helloя�"

If you continue typing, the application will crash entirely with an assertion failure.

Relevant log output

[04:04:40] [Render thread/INFO] [STDERR/]: [imgui.ImGui$1:imAssertCallback:92]: Dear ImGui Assertion Failed: pos + bytes_count <= BufTextLen
[04:04:40] [Render thread/INFO] [STDERR/]: [imgui.ImGui$1:imAssertCallback:93]: Assertion Located At: /tmp/imgui/jni/imgui_widgets.cpp:3820
[04:04:40] [Render thread/INFO] [STDERR/]: [java.lang.Thread:dumpStack:1383]: java.lang.Exception: Stack trace
[04:04:40] [Render thread/INFO] [STDERR/]: [java.lang.Thread:dumpStack:1383]: 	at java.base/java.lang.Thread.dumpStack(Thread.java:1383)
[04:04:40] [Render thread/INFO] [STDERR/]: [java.lang.Thread:dumpStack:1383]: 	at imgui.ImGui$1.imAssertCallback(ImGui.java:94)
[04:04:40] [Render thread/INFO] [STDERR/]: [java.lang.Thread:dumpStack:1383]: 	at imgui.assertion.ImAssertCallback.imAssert(ImAssertCallback.java:21)
[04:04:40] [Render thread/INFO] [STDERR/]: [java.lang.Thread:dumpStack:1383]: 	at imgui.ImGuiInputTextCallbackData.deleteChars(Native Method)
@phoenix-the-uncreative phoenix-the-uncreative added the bug Something isn't working label Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant