First, you should explain what you're actually trying to do in real-life terms in your code. You might just overcomplicating this, and be digging yourself a deeper hole by focusing on shapes.size()-1 not working... so, first.
I suggest reading each line of code, out loud, to a rubber duck (or other cute object): https://en.wikipedia.org/wiki/Rubber_duck_debugging
In fact, I demand you to do this. You're probably thinking it's dumb and won't help. Well, it can.
That being said, after you think about the problem and talk to a rubber duck, if you're still having trouble:
Looping on shapes.size() is a bad idea when you are mutating the shapes vector itself within the loop, unless you're being careful. If shapes.size() is 0, shapes.size()-1 becomes the largest possible size_t (an unsigned integral type).
Perhaps save the shapes.size() variable into a variable before the loop so that you know you're working with a constant size for each iteration?
Why not loop from x = 1 to shape.size() and then offset everything by -1 so that you know you're not going to hit a negative number? Don't do shapes.size()-1 unless you absolutely can't think of any other way.
When you erase things, your vector size changes. Have a fullproof way to keep track of this.
Also, these algorithms remove_if
, might help. http://en.cppreference.com/w/cpp/algorithm/remove
Unless you're doing this for an assignment, and aren't allowed to use certain parts of the standard library, then it really should be your first resource to avoid reinventing the wheel.