Skip to content

fix(controller): serialize ticks with speed changes, reset and load - #74

Merged
rmouahid merged 1 commit into
developfrom
feature/73-prevent-concurrent-ticks
Nov 22, 2026
Merged

rmouahid merged 1 commit into
developfrom
feature/73-prevent-concurrent-ticks

Conversation

@rmouahid

Copy link
Copy Markdown
Owner

Context

setTickDelay stopped and restarted the loop thread without waiting: the old thread could still run a tick, so two threads ticked at once. reset, stepBack and 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 are synchronized; new reset() 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

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
@rmouahid
rmouahid merged commit d33d21c into develop Nov 22, 2026
1 check passed
@rmouahid
rmouahid deleted the feature/73-prevent-concurrent-ticks branch November 22, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant