The problem is that you use a loop from 0 to N when the valid indices are from 0 to N - 1. That's why you get an exception at the last iteration: std::vector::at
performs a binding check if you don't use borders, and then std::out_of_range
.
You need to change the loop condition to <
, not <=
.
for (int i = 0; i < x_captured.size(); i++) { for (int j = 0; j < y_captured.size(); j++) { ... } }
source share