Skip to content

THREE.clock.getElapsedTime has a side effect invalidating .getDelta() #5696

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

Closed
AndrewRayCode opened this issue Nov 29, 2014 · 7 comments
Closed

Comments

@AndrewRayCode
Copy link
Contributor

https://github.com/mrdoob/three.js/blob/master/src/core/Clock.js#L40

If the user's render function calls both getElapsedTime and getDelta in a requestAnimationFrame, the code will not work properly and it will be impossible to debug why without the "aha" moment of looking at the source. These two functions should not conflict with each other.

It's because getElapseTime calls getDelta, so for example if your code looks like this:

var elapsed = clock.getElapsedTime(),
    delta = clock.getDelta();

the delta will actually be the time between those two var statements!

A workaround for now is to call getDelta() first, which will get the delta between getDelta and the last getElapsedTime call, which is not ideal.

@mrdoob
Copy link
Owner

mrdoob commented Nov 30, 2014

Uh oh!
Yeah... The design of Clock is dangerous...

AndrewRayCode added a commit to AndrewRayCode/three.js that referenced this issue Aug 26, 2015
See mrdoob#5696 - adds a function to
update elapsed time since the math is done in two places. As far as I
can tell, getDelta() shouldn't care about the elapsed time, so I removed
the calculation from there.
AndrewRayCode added a commit to AndrewRayCode/three.js that referenced this issue Aug 26, 2015
See mrdoob#5696 - adds a function to
update elapsed time since the math is done in two places. As far as I
can tell, getDelta() shouldn't care about the elapsed time, so I removed
the calculation from there.
@AndrewRayCode
Copy link
Contributor Author

@spbond
Copy link

spbond commented Jun 10, 2017

In issue #11444 I also noted this problem, along with some others, and proposed some code which would completely decouple the two functions from each other. The changes I proposed are based on r85.

@Lowlet
Copy link

Lowlet commented Jun 6, 2021

I just lost two days trying to play animation because of this. Thank god i found this thread. Can this be at least mentioned in the Clock docs?

@weilueluo
Copy link

weilueluo commented Oct 13, 2022

Spent a solid hour debugging my program and finally found this... how is this an Enhancement not a Bug?

@manake
Copy link

manake commented Nov 3, 2022

This issue is opened since 2014 and this is still a bug.

Most importantly: The current clock doesn't allow to pause() and resume(), so it's entirely useless in some use cases and the only solution is to create a different clock class because sometimes no workaround is possible with current THREE.Clock.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 10, 2024

At this point, please use the new Timer class if you experience issues with Clock.

@Mugen87 Mugen87 closed this as completed Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants