Skip to content

Commit ba6472e

Browse files
committed
tweak: Improve error-handling in case of bad data
1 parent 4c039b9 commit ba6472e

File tree

2 files changed

+8
-2
lines changed
  • GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus
  • Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus

2 files changed

+8
-2
lines changed

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,14 @@ void PopulateReplayFileListbox(GameWindow *listbox)
274274
// extra
275275
UnicodeString extraStr;
276276

277+
if (header.endTime < header.startTime)
278+
header.startTime = 0;
279+
277280
time_t totalSeconds = header.endTime - header.startTime;
278281
UnsignedInt hours = totalSeconds / 3600;
279282
UnsignedInt mins = (totalSeconds % 3600) / 60;
280283
UnsignedInt secs = totalSeconds % 60;
281-
Real fps = header.frameCount / totalSeconds;
284+
Real fps = totalSeconds > 0 ? header.frameCount / totalSeconds : 0;
282285
extraStr.format(L"%02u:%02u:%02u (%g fps)", hours, mins, secs, fps);
283286

284287
if (header.localPlayerIndex >= 0)

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,14 @@ void PopulateReplayFileListbox(GameWindow *listbox)
274274
// extra
275275
UnicodeString extraStr;
276276

277+
if (header.endTime < header.startTime)
278+
header.startTime = 0;
279+
277280
time_t totalSeconds = header.endTime - header.startTime;
278281
UnsignedInt hours = totalSeconds / 3600;
279282
UnsignedInt mins = (totalSeconds % 3600) / 60;
280283
UnsignedInt secs = totalSeconds % 60;
281-
Real fps = header.frameCount / totalSeconds;
284+
Real fps = totalSeconds > 0 ? header.frameCount / totalSeconds : 0;
282285
extraStr.format(L"%02u:%02u:%02u (%g fps)", hours, mins, secs, fps);
283286

284287
if (header.localPlayerIndex >= 0)

0 commit comments

Comments
 (0)