diff --git a/java/com/google/scrollview/ui/SVWindow.java b/java/com/google/scrollview/ui/SVWindow.java index 267bfdda..ec16bd8a 100644 --- a/java/com/google/scrollview/ui/SVWindow.java +++ b/java/com/google/scrollview/ui/SVWindow.java @@ -204,10 +204,20 @@ public class SVWindow extends JFrame { super(name); // Provide defaults for sizes. - if (sizeX == 0) sizeX = canvasSizeX; - if (sizeY == 0) sizeY = canvasSizeY; - if (canvasSizeX == 0) canvasSizeX = sizeX; - if (canvasSizeY == 0) canvasSizeY = sizeY; + if (sizeX <= 0) sizeX = canvasSizeX; + if (sizeY <= 0) sizeY = canvasSizeY; + if (canvasSizeX <= 0) canvasSizeX = sizeX; + if (canvasSizeY <= 0) canvasSizeY = sizeY; + + // Avoid later division by zero. + if (sizeX <= 0) { + sizeX = 1; + canvasSizeX = sizeX; + } + if (sizeY <= 0) { + sizeY = 1; + canvasSizeY = sizeY; + } // Initialize variables nrWindows++;