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

ImDrawList::_OnChangedVtxOffset crash when scrolling a Multi-line Text Input with extremely long lines #3349

Closed
ncoder-1 opened this issue Jul 12, 2020 · 3 comments

Comments

@ncoder-1
Copy link

Version/Branch of Dear ImGui:

Dear ImGui 1.78 WIP (17703)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201402
define: __linux__
define: __GNUC__=10
--------------------------------
io.BackendPlatformName: imgui_impl_sdl
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000000
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMemoryCompactTimer = 60.0f
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Back-end/Renderer/Compiler/OS

Back-ends: "imgui_impl_sdl.h" "imgui_impl_opengl3.h"
Operating System: ArchLinux Linux 5.7.7-arch1-1 #1 SMP PREEMPT Wed, 01 Jul 2020 14:53:16 +0000 x86_64 GNU/Linux

My Issue/Question:

When using a Multi-line Text Input (in my case also with resize callback), if I paste text from clipboard or load a file with very long lines, scrolling will cause the following:

imgui_draw.cpp:520: void ImDrawList::_OnChangedVtxOffset(): Assertion `curr_cmd->VtxOffset != _CmdHeader.VtxOffset' failed.

Example text file: https://pastebin.com/raw/mPvzhXJ9

This is reproducible in the example_sdl_opengl3 demo.

Screenshots/Video

Screenshot from 2020-07-12 16-02-30

Standalone, minimal, complete and verifiable example: (see #2261)

example_sdl_opengl3: ../../imgui_draw.cpp:520: void ImDrawList::_OnChangedVtxOffset(): Assertion `curr_cmd->VtxOffset != _CmdHeader.VtxOffset' failed.
zsh: abort (core dumped)  ./example_sdl_opengl3
ocornut added a commit that referenced this issue Jul 12, 2020
…ne of text with more than ~16 KB characters. (#3349)
@ocornut
Copy link
Owner

ocornut commented Jul 12, 2020

Hello,

I can confirm this issue happens if you e.g. paste the given text twice.

One issue is we reserve vertices ahead for the worse case scenario (all characters visible) and in this case it makes us reserve above 64k at once, which is technically undefined but because most of the text ends up clipped it ends up fitting in much less and it all goes fine.

That unrelated assert catches it somehow by luck. It's not actually incorrect to remove that assert., so that's I'm doing that now. That would lift the issue for the majority use cases but isn't technically be 100% fail-proof.

ImFont::RenderText() has a comment referring to the more extreme/problematic version of this:

// Note that very large horizontal line will still be affected by the issue (e.g. a one megabyte string buffer without a newline will likely crash atm)

This issue is only affecting the lower-level ImDrawList::AddText() function, not ImGui:: functions.

There are many possible ways to tackle it, but I'm tempted to wait until upcoming text function refactor because support for alignment will lead us to know the length of each line, and therefore allow us to provide optimized clipping for horizontal lines.

@ocornut ocornut closed this as completed Jul 12, 2020
@ocornut
Copy link
Owner

ocornut commented Jul 12, 2020

To clarify: removing the asserts will effectively fix your issue.
There is still an unfixed issue with 16-bit indices, but it will manifest for much larger contents or for the unlikely case that more characters are simultaneously visible (e.g. small font, 4k screen). Will be addressed later.

@ncoder-1
Copy link
Author

Thanks for the quick update/fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants