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

Cannot subtract bevy::utils::Instant beyond the moment of app startup on WebAssembly #8483

Open
Seldom-SE opened this issue Apr 25, 2023 · 5 comments
Labels
A-Time Involves time keeping and reporting C-Bug An unexpected or incorrect behavior O-Web Specific to web (WASM) builds S-Blocked This cannot move forward until something else changes

Comments

@Seldom-SE
Copy link

Seldom-SE commented Apr 25, 2023

Bevy version

0.10

Relevant system information

WebAssembly

What you did

Attempted to represent an Instant that is before app startup by subtracting a Duration.

What went wrong

A panic due to subtraction with overflow!

Additional information

I have a feature in seldom_pixel that pre-simulates particles when you spawn an emitter. So, when something that emits particles gets close to being on-screen or a scene is spawned with an emitter already on-screen, you can spawn an emitter at that moment, and it will look like the particles were already there. Particles store the time they were spawned for their functionality, which means that pre-simulated particles may store a time before they were actually spawned.

On wasm, I can't represent particles that were spawned with pre-simulation too close to app startup, since that moment is not representable with Instant. Not a major issue, but it's hacky to workaround. A possible solution on my end would be to use f32s instead, or add a buffer to every time.last_update call. If it's possible, a solution on Bevy's end would be to start time somewhere after 0. A minute should suffice for me, but I think it wouldn't be a dent on Instant's range to start many years in.

@Seldom-SE Seldom-SE added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Apr 25, 2023
@alice-i-cecile alice-i-cecile added O-Web Specific to web (WASM) builds A-Time Involves time keeping and reporting D-Complex Quite challenging from either a design or technical perspective. Ask for help! and removed S-Needs-Triage This issue needs to be labelled labels Apr 25, 2023
@mockersf
Copy link
Member

mockersf commented Apr 25, 2023

Should be fixed by sebcrozet/instant#46

But also, it's maybe not supposed to work in native either, and will panic on other platforms depending on how much time you subtract

@mockersf mockersf added S-Blocked This cannot move forward until something else changes and removed D-Complex Quite challenging from either a design or technical perspective. Ask for help! labels Apr 25, 2023
@daxpedda
Copy link
Contributor

Was discussed here in detail: sebcrozet/instant#45 (comment)

[..] The starting point of the underlying clock is not defined by Rust.

The reason this currently works on Linux is because std uses clock_gettime:

All implementations support the system-wide realtime clock, which is identified by CLOCK_REALTIME. Its time represents seconds and nanoseconds since the Epoch.

So the starting time is since the UNIX epoch. So unless your computer boots with a time set to 1970 it will always be much bigger then 0.

On Windows for example, std uses QueryPerformanceCounter, which doesn't start from the UNIX epoch, 0 can be the start of when you boot. [..]

@james7132
Copy link
Member

We've moved from instant to web-time, is this still an issue?

@Seldom-SE
Copy link
Author

It still is. Repro: https://github.com/Seldom-SE/testetst/blob/4f1dc50d873868821104f5990edfddaefb17c5a9/src/main.rs

ERROR app: panicked at /home/seldom/.cargo/registry/src/index.crates.io-6f17d22bba15001f/web-time-0.2.4/src/time/insta
nt.rs:93:14:
overflow when subtracting duration from instant

@daxpedda
Copy link
Contributor

As pointed out in #8483 (comment) this isn't an issue with instant or web-time, but with the guarantees std::time::Instant gives, which both libraries try to emulate as closely as possible.

If Bevy wants to resolve this issue, it has to move away from std::time::Instant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Time Involves time keeping and reporting C-Bug An unexpected or incorrect behavior O-Web Specific to web (WASM) builds S-Blocked This cannot move forward until something else changes
Projects
None yet
Development

No branches or pull requests

5 participants