diff --git a/src/Magnum/DebugTools/FrameProfiler.cpp b/src/Magnum/DebugTools/FrameProfiler.cpp index b388f0040..1f06bcbdb 100644 --- a/src/Magnum/DebugTools/FrameProfiler.cpp +++ b/src/Magnum/DebugTools/FrameProfiler.cpp @@ -476,7 +476,11 @@ void FrameProfilerGL::setup(const Values values, const UnsignedInt maxFrameCount arrayAppend(measurements, InPlaceInit, "Frame time"_s, Units::Nanoseconds, UnsignedInt(Containers::arraySize(_state->frameTimeStartFrame)), [](void* state, UnsignedInt current) { - static_cast(state)->frameTimeStartFrame[current] = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); + /* Using steady_clock even though it might not be as precise as + high_resolution_clock in order to avoid the delta being + negative between frames, causing an underflow and an assert + similar to what used to happen for PrimitiveClipRatio */ + static_cast(state)->frameTimeStartFrame[current] = std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count(); }, [](void*, UnsignedInt) {}, [](void* state, UnsignedInt previous, UnsignedInt current) { @@ -490,11 +494,15 @@ void FrameProfilerGL::setup(const Values values, const UnsignedInt maxFrameCount arrayAppend(measurements, InPlaceInit, "CPU duration"_s, Units::Nanoseconds, [](void* state) { - static_cast(state)->cpuDurationStartFrame = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); + /* Using steady_clock even though it might not be as precise as + high_resolution_clock in order to avoid the delta being + negative between frames, causing an underflow and an assert + similar to what used to happen for PrimitiveClipRatio */ + static_cast(state)->cpuDurationStartFrame = std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count(); }, [](void* state) { /* libc++ 10 needs an explicit cast to UnsignedLong */ - return UnsignedLong(std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count() - static_cast(state)->cpuDurationStartFrame); + return UnsignedLong(std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()).count() - static_cast(state)->cpuDurationStartFrame); }, _state.get()); _state->cpuDurationIndex = index++; }