Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clock.getDelta() sometimes returns 0 which leads to division by 0 issues #737

Closed
pmi-gbs opened this issue Sep 10, 2024 · 3 comments · Fixed by #743
Closed

clock.getDelta() sometimes returns 0 which leads to division by 0 issues #737

pmi-gbs opened this issue Sep 10, 2024 · 3 comments · Fixed by #743
Labels
bug Something isn't working
Milestone

Comments

@pmi-gbs
Copy link
Contributor

pmi-gbs commented Sep 10, 2024

Describe the bug

I've noticed that in the EnvironmentControls, which broke the camera transform (NaN and the likes) and other values of it.

in:

update( deltaTime = Math.min( this.clock.getDelta(), 64 / 1000 ) )

It should probably defused right after this line (and other lines where a deltaTime is used) with something like:

deltaTime = Math.max( deltaTime, 0.000001 );

To Reproduce

Steps to reproduce the behavior:

Not sure, to be honest, took some time to find out, that getDelta() is allowed to return 0, it randomly occured, while moving around with the controls. It could be that update() was executed consecutively, but even then I don't think it should break the camera.

@pmi-gbs pmi-gbs added the bug Something isn't working label Sep 10, 2024
@gkjohnson gkjohnson added this to the v0.3.38 milestone Sep 11, 2024
@gkjohnson
Copy link
Contributor

gkjohnson commented Sep 11, 2024

Thanks - are you passing "deltaTime" in yourself? Or relying on the built in clock? Either way after testing by directly passing 0 in in a second update call it looks like this is causing an issue. I think an easy solution here is to just return early from the update function if is deltaTime <= 0 in EnvironmentControls and GlobeControls. Would you like to make a PR?

@gkjohnson
Copy link
Contributor

Fixed in #743. Without any more information about how this is happening in practice (update must be getting called back to back) checking for 0 seems like the most reasonable solution.

@pmi-gbs
Copy link
Contributor Author

pmi-gbs commented Sep 16, 2024

Yes it did happen with the default clock and my own clock as well. I wonder why though, as even consecutive calls of clock.getDelta() should intuitively return a value > 0, but I guess the precision of performance.now() is kinda bad (and because of all the security stuff got even worse up to > 100 us)

The merged fix is even better thanks. I checked the rest of the code-base and indeed these were the only concerning clock.getDelta() calls (as otherwise only delta * ... is done).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants