Skip to content

Commit

Permalink
Fix "Not in a step" exception with battle calc. (#10689)
Browse files Browse the repository at this point in the history
* Fix "Not in a step" exception w/ battle calc.

* Acquire write lock when saving game.
  • Loading branch information
asvitkine authored Jun 23, 2022
1 parent 27e8edc commit 1f65bc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@ public void setHistory(final History history) {

public void resetHistory() {
gameHistory = new History(this);
GameStep step = getSequence().getStep();
// Put the history in a round and step, so that child nodes can be added without errors.
gameHistory
.getHistoryWriter()
.startNextStep(
step.getName(),
step.getDelegate().getName(),
step.getPlayerId(),
step.getDisplayName());
}

/** Not to be called by mere mortals. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public static void saveGameUncompressed(
// write to temporary file first in case of error
try (ObjectOutputStream outStream = new ObjectOutputStream(sink)) {
outStream.writeObject(engineVersion);
try (GameData.Unlocker ignored = data.acquireReadLock()) {
try (GameData.Unlocker ignored = data.acquireWriteLock()) {
final var history = data.getHistory();
if (!options.withHistory) {
data.resetHistory();
Expand Down

0 comments on commit 1f65bc3

Please sign in to comment.