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

Floating-point issues rendering tables with over 500k rows #4779

Closed
rajdevsharma opened this issue Dec 2, 2021 · 6 comments
Closed

Floating-point issues rendering tables with over 500k rows #4779

rajdevsharma opened this issue Dec 2, 2021 · 6 comments

Comments

@rajdevsharma
Copy link

rajdevsharma commented Dec 2, 2021

Version/Branch of Dear ImGui:

Version: 1.85
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_dx11.cpp + imgui_impl_win32.cpp (or specify if using a custom engine/back-end)
Compiler: Visual Studio 2019
Operating System: Windows 10

My Issue/Question:

When I render a table with more than about 550k rows, I start noticing some artifacts on the scrolling behavior.

  1. A gap appears at the bottom of the table, where it looks like there is plenty of space where another row could have been drawn at the bottom of the table, but the space is blank. For example, in the screenshot, it looks like row 809935 should be displayed, but it is not.
  2. While dragging the vertical scrollbar, I stop moving the mouse (but still holding down the mouse button so the mouse drag is still active), and I would expect the scroll position to stop as well. However, the scroll position starts "flickering" up and down by a few pixels so every frame it scrolls up a few pixels and then back down a few pixels, over and over.

I assume these are both the same issue that coordinates are represented using float instead of double, so there is a loss of precision.

Do you think this is something that could be fixed in an upcoming release of Dear ImGui? Otherwise, what workaround might you suggest here? Maybe I make a fork and change all the coordinates to double instead of float?

I'm trying to develop a viewer for data entries where there could be millions of records, and the user can smoothly scroll through the list, and as the user scrolls, we fetch the appropriate entries to render. Getting this to work with ImGui has been a great experience - thank you for all your hard work developing this amazing library! If I could get the scrolling working smoothly for large tables, this would be a perfect solution for what I'm trying to build.

Screenshots/Video

table-issue

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

ImGui::SetNextWindowSize({ 1000, 1000 });
ImGui::Begin("Example");

static ImGuiTableFlags flags =
    ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable
    | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_NoBordersInBody
    | ImGuiTableFlags_ScrollY;
 
const float frameHeight = 500.0f;
if (ImGui::BeginTable("table_sorting", 1, flags, ImVec2(0.0f, frameHeight), 0.0f)) {
    ImGui::TableSetupColumn(
        "updTime",
        ImGuiTableColumnFlags_DefaultSort | ImGuiTableColumnFlags_WidthFixed,
        0.0f);

    ImGui::TableHeadersRow();
    ImGuiListClipper clipper;
    clipper.Begin(2'000'000);
    while (clipper.Step())
    {
        for (int row_n = clipper.DisplayStart; row_n < clipper.DisplayEnd; row_n++)
        {
            ImGui::PushID(std::to_string(row_n).c_str());
            ImGui::TableNextRow();
            ImGui::TableNextColumn();
            ImGui::Text("%04d", row_n);
            ImGui::PopID();
        }
    }
    ImGui::EndTable();
}
ImGui::End();
@ocornut
Copy link
Owner

ocornut commented Dec 2, 2021

This is a duplicate of #3962 #3609 and also ocornut/imgui_club#20
Best to keep the discussion in existing thread, thank you!

@ocornut ocornut closed this as completed Dec 2, 2021
@rajdevsharma
Copy link
Author

Ah sorry, I missed these. Thank you!

@ocornut
Copy link
Owner

ocornut commented Dec 2, 2021

There are multiple sides to this issue but I think if you provide a height to clipper.Begin() here it might improve the situation.

@rajdevsharma
Copy link
Author

Interesting! That does seem to make it quite a lot better so far from what I can see. Thank you for the tip!

@ocornut
Copy link
Owner

ocornut commented Dec 6, 2021

I've pushed improvements for this now, see #3609

@rajdevsharma
Copy link
Author

Amazing, thanks again!

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