fix(particles): report isPlaying() in sync with particle lifetime#8901
Merged
Conversation
A stopped or non-looping emitter reported isPlaying() true long after its particles died: endTime used the full spawn-all-particles estimate (max(rate,rate2)*numParticles + lifetime) on a wall clock. After stop() only the already-alive particles drain, so the budget is at most lifetime, and the wall clock also desynced under pause/timeScale. Measure endTime on the emitter's own simulation clock (simTimeTotal) and use a lifetime budget once emission halts (stop() and loop = false). Fixes #2146 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
particlesystem.isPlaying()returnedtruelong after a stopped or non-looping system's particles had visually died.endTimewas the full "spawn every particle and outlive the last one" estimate (max(rate, rate2) * numParticles + lifetime) anchored toDate.now(). But afterstop()(orloop = false) emission has already halted, so the only remaining work is the alive particles draining — at mostlifetime. The wall clock also desynced the playing state under pause /timeScale.This measures
endTimeon the emitter's own simulation clock (simTimeTotal, which only advances while ticking and not paused) and uses alifetimebudget once emission halts (stop()and theloop = falsesetter). Adds unit tests covering theisPlaying()state.Verified against the issue's repro project (built against this branch): after Stop the label flips to "stopped" at ~5s (the lifetime) instead of ~11s, and the state now survives a pause correctly.
Fixes #2146
Checklist
🤖 Generated with Claude Code