Преглед изворни кода

UI: Prevent negative "disk full in" calculation when no output

If the output is paused the average bitrate will be zero, resulting in
infinite time until disk is full and int overflows. Similarly, if no data
has been collected yet, the result will be NaN and undefined behavior.
Richard Stanway пре 2 година
родитељ
комит
930c65e7c3
1 измењених фајлова са 6 додато и 0 уклоњено
  1. 6 0
      UI/window-basic-stats.cpp

+ 6 - 0
UI/window-basic-stats.cpp

@@ -452,9 +452,15 @@ void OBSBasicStats::ResetRecTimeLeft()
 
 
 void OBSBasicStats::RecordingTimeLeft()
 void OBSBasicStats::RecordingTimeLeft()
 {
 {
+	if (bitrates.empty())
+		return;
+
 	long double averageBitrate =
 	long double averageBitrate =
 		accumulate(bitrates.begin(), bitrates.end(), 0.0) /
 		accumulate(bitrates.begin(), bitrates.end(), 0.0) /
 		(long double)bitrates.size();
 		(long double)bitrates.size();
+	if (averageBitrate == 0)
+		return;
+
 	long double bytesPerSec = (averageBitrate / 8.0l) * 1000.0l;
 	long double bytesPerSec = (averageBitrate / 8.0l) * 1000.0l;
 	long double secondsUntilFull = (long double)num_bytes / bytesPerSec;
 	long double secondsUntilFull = (long double)num_bytes / bytesPerSec;