Turns out it is impossible for a child's jointIndex to be larger than its parent's, so I removed the while() loop logic.