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

TextWrapped will cause too-many-vertices error for long single-line strings #7496

Closed
achabense opened this issue Apr 15, 2024 · 2 comments
Closed

Comments

@achabense
Copy link

achabense commented Apr 15, 2024

Version/Branch of Dear ImGui:

Version 1.90.5

Back-ends:

imgui_impl_sdl2.cpp + imgui_impl_sdlrenderer2.cpp

Compiler, OS:

Windows 10 + MSVC 2022

Full config/build information:

No response

Details:

ImGui::TextWrapped and other text functions using wrap-pos settings will cause too-many-vertices error when displaying long single-line strings.
image
Background: I met this problem when trying to TextWrapped the lines getline-ed from files. I got the assertion failure after unexpectedly opening a large non-text file (which does not contain \n).
Similar issue: #5720

Screenshots/Video:

The effect for the first example below:
image

Minimal, Complete and Verifiable Example code:

ImGui::SetNextWindowSize(ImVec2(300, 50), ImGuiCond_Always);
if (ImGui::Begin("Failed")) {
    std::string long_single_line(20000, 'a');
    ImGui::TextWrapped("%s", long_single_line.c_str());
}
ImGui::End();

The problem is not limited to TextWrapped. It can affect every text function via wrap-pos settings:

ImGui::SetNextWindowSize(ImVec2(300, 50), ImGuiCond_Always);
if (ImGui::Begin("Failed")) {
    ImGui::PushTextWrapPos(200);
    std::string long_single_line(20000, 'a');
    ImGui::TextUnformatted(long_single_line.data(), long_single_line.data() + long_single_line.size());
    ImGui::PopTextWrapPos();
}
ImGui::End();
@achabense achabense changed the title TextWrapped will cause too-many-vertices error for long single lines TextWrapped will cause too-many-vertices error for long single lines Apr 15, 2024
@achabense achabense changed the title TextWrapped will cause too-many-vertices error for long single lines TextWrapped will cause too-many-vertices error for long single-line strings Apr 15, 2024
@ocornut
Copy link
Owner

ocornut commented Apr 15, 2024

Thanks. I have pushed a mitigation: daecfff

This is a known issue, I don't envision a fuller fix before we replace the text functions (the new WIP text functions don't have this issue). With the mitigation however you are much less likely to encounter the issue, so it may be good enough.

@ocornut
Copy link
Owner

ocornut commented Apr 15, 2024

Closing this as I don't expect to fix the current codebase further, but with the mitigation it's more or less not any worse that any other functions.

the new WIP text functions don't have this issue

Actually I was wrong, they also DID have this issue, but I have managed to fix it in the new text functions (no ETA, sorry) for a negligible cost (one pointer compare per visible wrapped line):
image

@ocornut ocornut closed this as completed Apr 15, 2024
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