Reputation: 523
I am not new to arrays, but this is a very strange error. Whenever I try to call the removeAll method on a libgdx array, and I pass in the same array I called it on (To remove every element in the array) it causes this error :
Exception in thread "LWJGL Application" java.lang.IndexOutOfBoundsException: index can't be >= size: 2 >= 1
Keep in mind that I'm passing in the same array that is calling the removeAll method. I need to be able to clear the array so I can reuse it instead of creating lots of arrays.
Upvotes: 0
Views: 341
Reputation: 93789
It doesn't work because it's not designed to operate on itself. The removeAll method is iterating the array as it's shrinking and doesn't expect that.
Just call array.clear()
Upvotes: 4