How are you constructing your Array invalid index '0' usually means it's not there.
I've had a similar problem if I make and array then do a for loop.
for i in Array.Size():
then popfront at zero 1 now wants to be zero so isn't one any more so next when i look for one it's actually zero.
if you could elaborate on your code i'd be happy to help