Repository navigation
fix(controller): serialize ticks with speed changes, reset and load - #74
Merged
Merged
Conversation
Changing the speed restarted the loop thread while the old one could still be mid-tick, and reset, step back or loading a snapshot mutated the grid concurrently with a running tick. Every transition and every tick now runs under the simulator monitor, and a replaced loop thread exits before ticking again. The auto-stop on extinction runs on the JavaFX thread and re-checks that the fire is really out. Closes #73
This was referenced Nov 22, 2026
Closed
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.
Context
setTickDelaystopped and restarted the loop thread without waiting: the old thread could still run a tick, so two threads ticked at once.reset,stepBackand loading a snapshot also mutated the grid while a tick was in progress.Changes
SimulationController: every transition (start, pause, step, stop, reset, step back, speed change, load) runs under the simulator monitor. The loop ticks under the same monitor and exits as soon as it is no longer the active thread, so a replaced thread can never tick again.FireSimulator: grid, history and snapshot operations aresynchronized; newreset()restores the grid and clears history atomically.MainWindow: the automatic stop when the fire dies out runs on the JavaFX thread and re-checks the state and the grid first.Tests
repeatedSpeedChangesPreserveTheTickCount: 50 speed changes, the tick counter matches the snapshot tick.resetWaitsForAnInProgressTickAndRestoresEveryCell: reset requested mid-tick waits for it, then every cell matches its initial state (fails on the previous code).mvn test: 56/56 passed.Closes #73