Fixed stack overflow error when calling ClearDistToRootToValidDist.