Prevent NaN returned by getTotalLength