I’m going to be assuming a lot here about how you programed the array and data located within it, but a possible fix would simply be to Clamp the index value between min and max size of the array before accessing an element of the array. That way you can avoid any runtime errors and simply have to deal with logical errors surrounding that chunk of data in your code.