fix infinite loop in getBounds and setMaxBounds, close #1895, close #1866