diff --git a/src/position.cpp b/src/position.cpp index 0a275b5e..7725b934 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1662,6 +1662,18 @@ int Position::see(Square from, Square to) const { } +/// Position::setStartState() copies the content of the argument +/// inside startState and makes st point to it. This is needed +/// when the st pointee could become stale, as example because +/// the caller is about to going out of scope. + +void Position::setStartState(const StateInfo& s) { + + startState = s; + st = &startState; +} + + /// Position::clear() erases the position object to a pristine state, with an /// empty board, white to move, and no castling rights. diff --git a/src/position.h b/src/position.h index ae750697..676f68ef 100644 --- a/src/position.h +++ b/src/position.h @@ -240,6 +240,7 @@ public: bool square_is_weak(Square s, Color c) const; // Doing and undoing moves + void setStartState(const StateInfo& st); void do_move(Move m, StateInfo& st); void undo_move(Move m); void do_null_move(StateInfo& st); diff --git a/src/uci.cpp b/src/uci.cpp index b03752ed..6ce3bf85 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -22,6 +22,7 @@ //// Includes //// +#include #include #include #include @@ -228,6 +229,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); } } } @@ -321,6 +325,8 @@ namespace { if (moveTime) infinite = true; // HACK + assert(RootPosition.is_ok()); + think(RootPosition, infinite, ponder, RootPosition.side_to_move(), time, inc, movesToGo, depth, nodes, moveTime, searchMoves); }