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
1f2f46b27a
commit
fd5fdd8ebb
1 changed files with 14 additions and 0 deletions
|
@ -79,6 +79,12 @@ side_actions_container::side_actions_container()
|
|||
size_t side_actions_container::get_turn_impl(size_t begin, 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;
|
||||
}
|
||||
size_t mid = (begin+end) / 2;
|
||||
|
@ -219,6 +225,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
|
||||
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) {
|
||||
|
@ -227,6 +240,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