mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-19 00:26:33 +08:00
Detach the state when copying a position
In Position we store a pointer to a StateInfo record kept outside of the Position object. When copying a position we copy also that pointer so after the copy we have two Position objects pointing to the same StateInfo record. This can be dangerous so fix by copying also the StateInfo record inside the new Position object and let the new st pointer point to it. This completely detach the copied Position from the original one. Also rename setStartState() as saveState() and clean up the API to state more clearly what the function does. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
@@ -210,9 +210,9 @@ namespace {
|
||||
if (RootPosition.rule_50_counter() == 0)
|
||||
RootPosition.reset_game_ply();
|
||||
}
|
||||
// Our StateInfo st is about going out of scope,
|
||||
// so save its content before they disappear.
|
||||
RootPosition.setStartState(st);
|
||||
// Our StateInfo st is about going out of scope so copy
|
||||
// its content inside RootPosition before they disappear.
|
||||
RootPosition.saveState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user