The problem is that `current_mask` can become `selection.size()`. The loop could also be refactored to break out of it when the end of the selection is reached. This can be done separately.
The problem is that `current_mask` can become `selection.size()`. The loop could also be refactored to break out of it when the end of the selection is reached. This can be done separately.