progresstracker: Don't hand out NaN

When the duration is set to 0, clamp it to 1us. This way we're almost
correct: We should really instantly finish, but we don't. But we do
respect the delay.

Doing this properly would require some refactoring of how the progress
tracker actually maintains progress, and this is just a quick fix.
This commit is contained in:
Benjamin Otte 2017-11-12 06:19:00 +01:00
parent b2877605cf
commit efaa6524ac

View File

@ -82,7 +82,7 @@ gtk_progress_tracker_start (GtkProgressTracker *tracker,
tracker->is_running = TRUE;
tracker->last_frame_time = 0;
tracker->duration = duration;
tracker->iteration = - delay / (gdouble) duration;
tracker->iteration = - delay / (gdouble) MAX (duration, 1);
tracker->iteration_count = iteration_count;
}
@ -108,7 +108,7 @@ gtk_progress_tracker_finish (GtkProgressTracker *tracker)
**/
void
gtk_progress_tracker_advance_frame (GtkProgressTracker *tracker,
guint64 frame_time)
guint64 frame_time)
{
gdouble delta;
@ -127,7 +127,7 @@ gtk_progress_tracker_advance_frame (GtkProgressTracker *tracker,
return;
}
delta = (frame_time - tracker->last_frame_time) / gtk_slowdown / tracker->duration;
delta = (frame_time - tracker->last_frame_time) / gtk_slowdown / MAX (tracker->duration, 1);
tracker->last_frame_time = frame_time;
tracker->iteration += delta;
}