From 2a98042c21fa2f3f5630c41a16b91539d7da3b87 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 1 Jun 2013 15:45:46 +0200 Subject: [PATCH] Fix a crash when 'go' multiple times Search is started after setting a position and issuing UCI 'go' command. Then if we stop the search and call 'go' again without setting a new position it is assumed that the previous setup is preserved, but this is not the case because what happens is that SetupStates is reset to NULL, leading to a crash as soon as RootPos.is_draw() is called because st->previous is now stale. UCI protocol is not very clear about requiring that a position is setup always before launching a search, so here we easy the life of GUI developers assuming that the current state is preserved after returning from a 'stop' command. Bug reported by Gregor Cramer. No functional change. --- src/thread.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/thread.cpp b/src/thread.cpp index 782cf1ac..b7bead9f 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -366,10 +366,14 @@ void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits, Signals.stopOnPonderhit = Signals.firstRootMove = false; Signals.stop = Signals.failedLowAtRoot = false; + RootMoves.clear(); RootPos = pos; Limits = limits; - SetupStates = states; // Ownership transfer here - RootMoves.clear(); + if (states.get()) // If we don't set a new position, preserve current state + { + SetupStates = states; // Ownership transfer here + assert(!states.get()); + } for (MoveList it(pos); *it; ++it) if ( searchMoves.empty() -- 2.39.2