File tree Expand file tree Collapse file tree
engine/window-system/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -395,8 +395,18 @@ void AppFrame::onBeforeUpdate() {
395395 m_frame_rate_controller->update ();
396396 }
397397
398- m_fFPS = 1.0 / m_frame_rate_controller->getStatistics ()->getDuration (0 );
399- m_fAvgFPS = 1.0 / m_frame_rate_controller->getStatistics ()->getAverage (10 );
398+ // Avoid NaN/inf: only invert positive finite duration; use minimum duration to cap FPS and avoid 1/0
399+ constexpr double min_duration = 1e-6 ; // cap reported FPS at 1e6
400+ const auto * stats = m_frame_rate_controller->getStatistics ();
401+ double d0 = stats->getDuration (0 );
402+ if (d0 == d0 && d0 > 0.0 ) {
403+ m_fFPS = 1.0 / (d0 < min_duration ? min_duration : d0);
404+ }
405+ // Use 60-frame average so GetFPS is stable at high FPS (10-frame window was too noisy at 2000+ FPS)
406+ double avg = stats->getAverage (60 );
407+ if (avg == avg && avg > 0.0 ) {
408+ m_fAvgFPS = 1.0 / (avg < min_duration ? min_duration : avg);
409+ }
400410 m_frame_rate_controller->setFrameRate (m_target_fps);
401411 m_message_timer = core::ScopeTimer (&m_message_time);
402412}
Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ namespace core {
2121 l += 1 ;
2222 }
2323 }
24+ if (l == 0 ) {
25+ return 0.0 ;
26+ }
2427 return result / static_cast <double >(l);
2528 }
2629
You can’t perform that action at this time.
0 commit comments