Skip to content

Commit

Permalink
ImGuiIntegration: avoid assertions with zero delta time.
Browse files Browse the repository at this point in the history
Since v1.68, ImGui disallows zero delta time to "prevent subtle issues",
but due to a four-year-old bug in SDL2, this *does* cause subtle issues.

Co-authored-by: Andrew Huang <andyroiiid@live.com>
  • Loading branch information
mosra and andyroiiid committed Mar 22, 2020
1 parent a26f0ea commit e7dc17a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Magnum/ImGuiIntegration/Context.cpp
Expand Up @@ -272,6 +272,17 @@ void Context::newFrame() {

ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = _timeline.previousFrameDuration();
/* Since v1.68 and https://github.com/ocornut/imgui/commit/3c07ec6a6126fb6b98523a9685d1f0f78ca3c40c,
ImGui disallows zero delta time to "prevent subtle issues".
Unfortunately that *does* cause subtle issues, especially in combination
with SDL2 on Windows -- when the window is being dragged across the
screen, SDL temporarily halts all event processing and then fires all
pending events at once, causing zero delta time. A bugreport for this
is opened since 2016 -- https://bugzilla.libsdl.org/show_bug.cgi?id=2077
but there was nothing done last time I checked (March 2020). More info
also at https://github.com/mosra/magnum-integration/issues/57 */
if(ImGui::GetFrameCount() != 0)
io.DeltaTime = Math::max(io.DeltaTime, std::numeric_limits<float>::epsilon());

/* Fire delayed mouse events. This sets MouseDown both in case the press
happened in this frame but also if both press and release happened at
Expand Down

0 comments on commit e7dc17a

Please sign in to comment.