Skip to content

Commit

Permalink
Fix assert with custom synced AI commands
Browse files Browse the repository at this point in the history
Function run() at the beginning of synced_context.cpp asserts when a command is configured not to be undoable (use_undo=false), but the undo stack is not empty (resources::undo_stack->can_undo() returns true). Thus, the undo stack needs to be cleared before executing commands that are not supposed to be undoable.

Most AI commands use use_undo=false, but custom synced commands route through do_command, which uses a hard-coded use_undo=true. That, by itself, is not a problem, but if the next AI action uses use_undo and does not clear the undo stack first, the assert is triggered. AI actions with use_undo=false therefore need to clear the undo stack. This commit adds that for recruiting and recalling, the only AI actions that did not already do so.
  • Loading branch information
mattsc committed Jun 10, 2021
1 parent 6ebad14 commit 7b250e2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ai/actions.cpp
Expand Up @@ -32,6 +32,7 @@
* So far the use of 'subjective info' is stubbed out.
*/

#include "actions/undo.hpp"
#include "ai/actions.hpp"
#include "ai/manager.hpp"
#include "ai/simulated_actions.hpp"
Expand Down Expand Up @@ -652,6 +653,7 @@ void recall_result::do_execute()
// Do the actual recalling.
// We ignore possible errors (=unit doesn't exist on the recall list)
// because that was the previous behavior.
resources::undo_stack->clear();
synced_context::run_in_synced_context_if_not_already("recall",
replay_helper::get_recall(unit_id_, recall_location_, recall_from_),
false,
Expand Down Expand Up @@ -800,6 +802,7 @@ void recruit_result::do_execute()
return;
}

resources::undo_stack->clear();
synced_context::run_in_synced_context_if_not_already("recruit", replay_helper::get_recruit(u->id(), recruit_location_, recruit_from_), false, !preferences::skip_ai_moves());
//TODO: should we do something to pass use_undo = false in replays and ai moves ?
//::actions::recruit_unit(*u, get_side(), recruit_location_, recruit_from_,
Expand Down

0 comments on commit 7b250e2

Please sign in to comment.