mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Fix a subtle bug due to the StateInfo pointer became stale
There was one occurence when the StateInfo variable went out of scope before the corresponding Position object. This yelds to a crash. Bug was not hit before because occurs only when using an UCI interface and not the usual benchmark. The fix consists in copying internally the content of the about to stale StateInfo. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
962216440c
commit
55f9afee2a
3 changed files with 19 additions and 0 deletions
|
@ -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
|
/// Position::clear() erases the position object to a pristine state, with an
|
||||||
/// empty board, white to move, and no castling rights.
|
/// empty board, white to move, and no castling rights.
|
||||||
|
|
||||||
|
|
|
@ -240,6 +240,7 @@ public:
|
||||||
bool square_is_weak(Square s, Color c) const;
|
bool square_is_weak(Square s, Color c) const;
|
||||||
|
|
||||||
// Doing and undoing moves
|
// Doing and undoing moves
|
||||||
|
void setStartState(const StateInfo& st);
|
||||||
void do_move(Move m, StateInfo& st);
|
void do_move(Move m, StateInfo& st);
|
||||||
void undo_move(Move m);
|
void undo_move(Move m);
|
||||||
void do_null_move(StateInfo& st);
|
void do_null_move(StateInfo& st);
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
//// Includes
|
//// Includes
|
||||||
////
|
////
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -228,6 +229,9 @@ namespace {
|
||||||
if (RootPosition.rule_50_counter() == 0)
|
if (RootPosition.rule_50_counter() == 0)
|
||||||
RootPosition.reset_game_ply();
|
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)
|
if (moveTime)
|
||||||
infinite = true; // HACK
|
infinite = true; // HACK
|
||||||
|
|
||||||
|
assert(RootPosition.is_ok());
|
||||||
|
|
||||||
think(RootPosition, infinite, ponder, RootPosition.side_to_move(), time,
|
think(RootPosition, infinite, ponder, RootPosition.side_to_move(), time,
|
||||||
inc, movesToGo, depth, nodes, moveTime, searchMoves);
|
inc, movesToGo, depth, nodes, moveTime, searchMoves);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue