wb: more robust side_actions_container::erase
i don't really know why the old code had a special case for `get_turn(next) != turn_of_position`, from what i see `turn_end(0)` would basicially return the same value as `next`. The new code removes that special case which resulted in assertion failures before (#1841) and also consiers the case where `position` appears multiple times in `turn_beginnings_`
This commit is contained in:
parent
ba6495c96a
commit
195913fc4b
1 changed files with 14 additions and 0 deletions
|
@ -78,6 +78,12 @@ side_actions_container::side_actions_container()
|
|||
std::size_t side_actions_container::get_turn_impl(std::size_t begin, std::size_t end, const_iterator it) const
|
||||
{
|
||||
if(begin+1 >= end) {
|
||||
if(begin+1 != end) {
|
||||
ERR_WB << "get_turn: begin >= end\n";
|
||||
}
|
||||
else if(it < turn_beginnings_[begin]) {
|
||||
ERR_WB << "get_turn failed\n";
|
||||
}
|
||||
return begin;
|
||||
}
|
||||
std::size_t mid = (begin+end) / 2;
|
||||
|
@ -218,6 +224,13 @@ side_actions_container::iterator side_actions_container::erase(iterator position
|
|||
turn_beginnings_.pop_back();
|
||||
}
|
||||
} else {
|
||||
#if 1
|
||||
for(auto& it : turn_beginnings_) {
|
||||
if (it == position) {
|
||||
it = next;
|
||||
}
|
||||
}
|
||||
#else
|
||||
std::size_t turn_of_position = std::distance(turn_beginnings_.begin(), beginning);
|
||||
// If we still have action this turn
|
||||
if(get_turn(next) == turn_of_position) {
|
||||
|
@ -226,6 +239,7 @@ side_actions_container::iterator side_actions_container::erase(iterator position
|
|||
assert(turn_of_position == 0);
|
||||
*beginning = turn_end(0); // Otherwise, we are emptying the current turn.
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue