From abeae0b7fa4fc1f169fe51a00730868832782020 Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Tue, 15 Jun 2021 06:37:22 +0800 Subject: [PATCH] init so that pointers are present --- pyqtgraph/graphicsItems/ScatterPlotItem.py | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pyqtgraph/graphicsItems/ScatterPlotItem.py b/pyqtgraph/graphicsItems/ScatterPlotItem.py index 99f1ec76..e40bc456 100644 --- a/pyqtgraph/graphicsItems/ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/ScatterPlotItem.py @@ -173,19 +173,21 @@ def _mkBrush(*args, **kwargs): class PixmapFragments: def __init__(self): - self._array = np.empty((0, 10), dtype=np.float64) - self.ptrs = None + self.alloc(0) + + def alloc(self, size): + self.arr = np.empty((size, 10), dtype=np.float64) + if QT_LIB.startswith('PyQt'): + self.ptrs = list(map(sip.wrapinstance, + itertools.count(self.arr.ctypes.data, self.arr.strides[0]), + itertools.repeat(QtGui.QPainter.PixmapFragment, self.arr.shape[0]))) + else: + self.ptrs = wrapInstance(self.arr.ctypes.data, QtGui.QPainter.PixmapFragment) def array(self, size): - if size > self._array.shape[0]: - self._array = np.empty((size + 16, 10), dtype=np.float64) - if QT_LIB.startswith('PyQt'): - self.ptrs = list(map(sip.wrapinstance, - itertools.count(self._array.ctypes.data, self._array.strides[0]), - itertools.repeat(QtGui.QPainter.PixmapFragment, self._array.shape[0]))) - else: - self.ptrs = wrapInstance(self._array.ctypes.data, QtGui.QPainter.PixmapFragment) - return self._array[:size] + if size > self.arr.shape[0]: + self.alloc(size + 16) + return self.arr[:size] def draw(self, painter, size, pixmap): if QT_LIB.startswith('PyQt'):