Skip to content

Fix: Handle edge case where intervalSum is zero during quick recordings - #192

Merged
binarykitchen merged 1 commit into
masterfrom
fix/avgfps-undefined-error
Aug 18, 2026
Merged

Fix: Handle edge case where intervalSum is zero during quick recordings#192
binarykitchen merged 1 commit into
masterfrom
fix/avgfps-undefined-error

Conversation

@binarykitchen

Copy link
Copy Markdown
Owner

Description

This PR fixes an edge case in the avgFps calculation that was causing an error when processing very quick video recordings.

Root Cause

The getAvgFps() and getAvgInterval() methods used a falsy check (if (!intervalSum)) to validate the elapsed time. This incorrectly treats 0 as an invalid value, even though zero milliseconds is a valid elapsed time for extremely brief recordings.

JavaScript truthy/falsy issue:

  • if (!0) evaluates to true (0 is falsy)
  • if (!intervalSum) returns undefined when intervalSum = 0
  • Result: avgFps becomes undefined instead of calculating correctly

Impact

This caused the following error in the server during poster generation:

Error: Average FPS cannot be undefined, zero or less: undefined

Affected recordings: Very quick recordings where the elapsed time rounds to 0ms

Solution

Replaced falsy checks with explicit validation:

  • Explicitly check for undefined, null, or values <= 0
  • Allows zero to be treated as a valid (though edge case) elapsed time value
  • Ensures avgFps calculation works for all recording durations

Testing

The fix handles all these scenarios:

  • Normal recordings: ✓ Works as before
  • Very quick recordings (< ~50ms): ✓ Now works instead of failing
  • No recording (intervalSum = undefined): ✓ Still returns undefined
  • Invalid data: ✓ Properly handled with explicit checks

Files Changed

  • src/wrappers/visuals/recorder.ts
    • Updated getAvgInterval() validation
    • Updated getAvgFps() validation

@binarykitchen
binarykitchen force-pushed the fix/avgfps-undefined-error branch from ca77763 to 31c806a Compare August 18, 2026 08:17
- Replace truthy/falsy check with explicit validation in getAvgInterval()
- Replace truthy/falsy check with explicit validation in getAvgFps()
- Issue: JavaScript treats 0 as falsy, causing avgFps to become undefined
- Impact: Prevents 'Average FPS cannot be undefined' error on poster generation
- Root cause: Very quick recordings may have intervalSum = 0, triggering falsy check

The fix ensures avgFps calculation works correctly for all recording durations,
even extremely brief recordings where elapsed time is 0.
@binarykitchen
binarykitchen force-pushed the fix/avgfps-undefined-error branch from 31c806a to 893152d Compare August 18, 2026 08:28
@binarykitchen
binarykitchen merged commit d5e93eb into master Aug 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant