Skip to content

Commit

Permalink
wb: more robust side_actions_container::erase
Browse files Browse the repository at this point in the history
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_`
  • Loading branch information
gfgtdf committed Apr 30, 2018
1 parent 1f2f46b commit fd5fdd8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/whiteboard/side_actions.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
}

Expand Down

0 comments on commit fd5fdd8

Please sign in to comment.