mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-01 05:10:41 +00:00
ProgressBar with fraction == NaN leads to gigantic allocation #7451
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#7451
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Version/Branch of Dear ImGui:
Version 1.90.5 (19046), Branch: docking (master/docking/etc.)
Back-ends:
Backend independent
Compiler, OS:
Visual Studio 2022 MSVC C++ 20
Full config/build information:
Details:
Reproduction:
Explanation:
Passing NaN to a ProgressBar widget with FrameRounding != 0 leads to a giant allocation in PathArcTo.
In my specific case this happens due to us calculating the fraction for the progress bar as
Count / (float)MaxCount, which happens to be able to become a0 / (float)0.Now, shame on us for dividing through 0 but it seems to me like that would be a pretty common expression to use for a progress bar and therefore a mistake that is easily made.
Now
ProgressBarcalls ImSaturate internally onfractionwhich e.g. properly prevents issues when fraction equals infinity.However NaN seems to stay NaN.
This NaN gets then passed down to
RenderRectFilledRangeH.IMPORTANT: If FrameRounding is set to 0,
RenderRectFilledRangeHwill exit out early and while the values calculated from NaN are still wrong, it is not critical forAddRectFilled. It may look wrong but doesn't crash.With frame rounding enabled however, a variation of Path...To will get used to draw the rounded rectangle.
And PathArcTo for example will allocate. I did not look exactly into how the NaN influences the number of path points. I also had different results in our application as opposed to a fresh imgui clone example.
However from that point it is easy to see that things go wrong and lead to a giant allocation in
_Path.reserve.The fix is not exactly difficult (just a check in ProgressBar) but it raises the quesiton if maybe
PathArcToitself should be more robust against this kind of input. That may be up to discussion and probably better decided by someone else.Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
No response