Skip to content

Commit 2327ef7

Browse files
marksammanmarkus-wa
authored andcommitted
Fix divide by zero in common.DemoHeader.FrameTime (#109)
* Return 0 in common.DemoHeader.FrameTime if PlaybackFrames is 0 to avoid dividing by zero Co-Authored-By: marksamman <mark.samman@gmail.com>
1 parent 70e8ef9 commit 2327ef7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

common/common.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ func (h DemoHeader) FrameRate() float64 {
4141
}
4242

4343
// FrameTime returns the time a frame / demo-tick takes in seconds.
44+
//
45+
// Returns 0 if PlaybackTime or PlaybackFrames are 0 (corrupt demo headers).
4446
func (h DemoHeader) FrameTime() time.Duration {
47+
if h.PlaybackFrames == 0 {
48+
return 0
49+
}
4550
return time.Duration(h.PlaybackTime.Nanoseconds() / int64(h.PlaybackFrames))
4651
}
4752

0 commit comments

Comments
 (0)