Use indices instead of pointers to avoid accessing elements beyond the end of the result mesh arrays.