Skip to content

fix(core): app delta is unclamped, so a hidden tab makes huge physics steps #517

Open

Description

@Exeloo

Which package is this bug report for?

core

Issue description

The game loop sets ctx.app.delta to the wall-clock time since the previous tick, with no upper bound: nanoforge-application.ts#L113, setDelta(step ? tickLengthMs : tickStart - previousTick). The loop is scheduled with timers, which browsers throttle to about one tick per second in a hidden tab.

So after the tab is hidden, or after any hitch, a system that moves by delta (components-systems move2D) makes one huge step. Fast bodies then pass through colliders that only test overlap: in the examples' local pong, a ball at 1000 px/s skips a 130 px wall-plus-ball span on any tick over 130 ms, leaves the field and was never served again (the game locked). The examples now cap the ball speed and serve a lost ball again, which hides the lock but not the tunnelling.

Found by the quality gate of NanoForge-dev/examples#18.

Code sample

// a system that moves by delta, as move2D does
position.x += velocity.x * (ctx.app.delta / 1000);
// hide the tab for 5 s: the next tick's delta is about 1000 ms

Versions

  • @nanoforge-dev/core 3.0.0
  • Chrome, Linux

Issue priority

Medium (should be fixed soon)

I have tested this issue on a development release

ed8c7e0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackages:coreRelated to Core library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions