Skip to content

Commit

Permalink
Fix divide by zero in common.DemoHeader.FrameTime (#109)
Browse files Browse the repository at this point in the history
* Return 0 in common.DemoHeader.FrameTime if PlaybackFrames is 0 to avoid dividing by zero

Co-Authored-By: marksamman <mark.samman@gmail.com>
  • Loading branch information
marksamman authored and markus-wa committed Apr 8, 2019
1 parent 70e8ef9 commit 2327ef7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ func (h DemoHeader) FrameRate() float64 {
}

// FrameTime returns the time a frame / demo-tick takes in seconds.
//
// Returns 0 if PlaybackTime or PlaybackFrames are 0 (corrupt demo headers).
func (h DemoHeader) FrameTime() time.Duration {
if h.PlaybackFrames == 0 {
return 0
}
return time.Duration(h.PlaybackTime.Nanoseconds() / int64(h.PlaybackFrames))
}

Expand Down

0 comments on commit 2327ef7

Please sign in to comment.