diff --git a/common/rendering.h b/common/rendering.h index ed0b525000..d317d31a2b 100644 --- a/common/rendering.h +++ b/common/rendering.h @@ -59,7 +59,8 @@ namespace rs2 : _counter(0), _delta(0), _last_timestamp(0), - _num_of_frames(0) + _num_of_frames(0), + _last_frame_counter(0) {} fps_calc(const fps_calc& other) @@ -75,7 +76,7 @@ namespace rs2 std::lock_guard lock(_mtx); if (++_counter >= _skip_frames) { - if (_last_timestamp != 0) + if (_last_timestamp != 0 && frame_counter > _last_frame_counter) { _delta = timestamp - _last_timestamp; _num_of_frames = frame_counter - _last_frame_counter; @@ -90,7 +91,7 @@ namespace rs2 double get_fps() const { std::lock_guard lock(_mtx); - if (_delta == 0) + if (std::abs(_delta) < std::numeric_limits::epsilon()) return 0; return (static_cast(_numerator) * _num_of_frames) / _delta;