bevyengine / bevyengine/bevy

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

Open
#8,483 5 comments 0 reactions 0 assignees View on GitHub
A-Time C-Bug O-Web S-Blocked
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## 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 `f32`s 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.