Skip to content

Commit

Permalink
fix OOS caused by undo stack missmatch
Browse files Browse the repository at this point in the history
see https://gna.org/bugs/?23323 for more description
  • Loading branch information
gfgtdf committed Feb 26, 2015
1 parent 781df37 commit 1fa8a29
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/replay.cpp
Expand Up @@ -978,7 +978,12 @@ static std::map<int, config> get_user_choice_internal(const std::string &name, c
//this should never change during the execution of this function.
const int current_side = resources::controller->current_side();
const bool is_mp_game = network::nconnections() != 0;

// whether sides contains a side that is not the currently active side.
const bool contains_other_side = !sides.empty() && (sides.size() != 1 || sides.find(current_side) == sides.end());
if(contains_other_side)
{
synced_context::set_is_simultaneously();
}
std::map<int,config> retv;
/*
when we got all our answers we stop.
Expand Down
10 changes: 7 additions & 3 deletions src/synced_context.cpp
Expand Up @@ -182,6 +182,11 @@ void synced_context::reset_is_simultaneously()
is_simultaneously_ = false;
}

void synced_context::set_is_simultaneously()
{
is_simultaneously_ = true;
}

bool synced_context::can_undo()
{
//this method should only works in a synced context.
Expand Down Expand Up @@ -217,8 +222,6 @@ namespace

void synced_context::pull_remote_user_input()
{
//we sended data over the network.
is_simultaneously_ = true;
//code copied form persist_var, feels strange to call ai::.. functions for something where the ai isn't involved....
//note that ai::manager::raise_sync_network isn't called by the ai at all anymore (one more reason to put it somehwere else)
try{
Expand All @@ -239,7 +242,7 @@ void synced_context::pull_remote_user_input()

void synced_context::send_user_choice()
{
is_simultaneously_ = true;
assert(is_simultaneously_);
syncmp_registry::send_user_choice();
}

Expand Down Expand Up @@ -267,6 +270,7 @@ static void send_require_random()

config synced_context::ask_server_for_seed()
{
set_is_simultaneously();
resources::controller->increase_server_request_number();
std::string name = "random_seed";
assert(get_synced_state() == synced_context::SYNCED);
Expand Down
4 changes: 4 additions & 0 deletions src/synced_context.hpp
Expand Up @@ -108,6 +108,10 @@ class synced_context
sets is_simultaneously_ = false, called when entering the synced context.
*/
static void reset_is_simultaneously();
/*
sets is_simultaneously_ = true, called using a user choice that is not the currently plaing side.
*/
static void set_is_simultaneously();
/**
@return whether there were recently no methods called that prevent undoing.
*/
Expand Down

0 comments on commit 1fa8a29

Please sign in to comment.