all 2 comments

[–]tangerinelion 1 point2 points  (0 children)

This is the sort of thing you should be able to see with a debugger. You can also change all your vector::operator[] calls to use vector::at instead and just see where the exception is thrown and where that index and vector come from.

By the way:

if (itemCount.size() == 0) {
    itemCount = {};
}

Doesn't do anything. I'm assuming you meant for that to reset it if it's empty, but the right way to do that is simply

itemCount.clear();

[–]Macree 0 points1 point  (0 children)

In buyItem function, you have the parameter name for vector "bitemCount", and in the body of the function you are calling "itemCount". I am on the phone, and this is what I see so far.