Fix possible crash when the index is greater than the number of element in the color array