diff --git a/pyqtgraph/graphicsItems/ImageItem.py b/pyqtgraph/graphicsItems/ImageItem.py index 5b041433..744e1937 100644 --- a/pyqtgraph/graphicsItems/ImageItem.py +++ b/pyqtgraph/graphicsItems/ImageItem.py @@ -291,8 +291,8 @@ class ImageItem(GraphicsObject): y = self.mapToDevice(QtCore.QPointF(0,1)) w = Point(x-o).length() h = Point(y-o).length() - xds = max(1, int(1/w)) - yds = max(1, int(1/h)) + xds = int(1/max(1, w)) + yds = int(1/max(1, h)) image = fn.downsample(self.image, xds, axis=0) image = fn.downsample(image, yds, axis=1) else: diff --git a/pyqtgraph/graphicsItems/tests/test_ImageItem.py b/pyqtgraph/graphicsItems/tests/test_ImageItem.py new file mode 100644 index 00000000..c2ba58d9 --- /dev/null +++ b/pyqtgraph/graphicsItems/tests/test_ImageItem.py @@ -0,0 +1,24 @@ +import gc +import weakref +# try: +# import faulthandler +# faulthandler.enable() +# except ImportError: +# pass + +from pyqtgraph.Qt import QtCore, QtGui, QtTest +import numpy as np +import pyqtgraph as pg +app = pg.mkQApp() + + +def test_dividebyzero(): + import pyqtgraph as pg + im = pg.image(pg.np.random.normal(size=(100,100))) + im.imageItem.setAutoDownsample(True) + im.view.setRange(xRange=[-5+25, 5e+25],yRange=[-5e+25, 5e+25]) + app.processEvents() + QtTest.QTest.qWait(1000) + # must manually call im.imageItem.render here or the exception + # will only exist on the Qt event loop + im.imageItem.render()