PyQtGraph:为什么调用gl.GLMeshItem.setMeshData()会泄漏内存?

时间:2019-02-06 14:32:42

标签: python-3.x pyqt pyqtgraph

当我使用其方法.setMeshData()更新gl.GLMeshItem()的顶点时,每次更新时都会释放内存。您可以在下面的示例中将n_tri简化为;;

(Python 3.5,Qt 5.6.2,pyqtgraph 0.10.0)

有什么想法会导致这种情况,以及是否有解决方法或解决方案?

工作示例:

# -*- coding: utf-8 -*-
from pyqtgraph.Qt import QtGui, QtCore

import numpy as np
import pyqtgraph as pg

import pyqtgraph.opengl as gl

app = QtGui.QApplication([])
mw = QtGui.QMainWindow()
mw.setWindowTitle('pyqtgraph example: PlotWidget')
mw.resize(800,800)
cw = QtGui.QWidget()
mw.setCentralWidget(cw)

l = QtGui.QGridLayout()

#l.setRowMinimumHeight(0, 400)
cw.setLayout(l)

w = gl.GLViewWidget()
w.setBackgroundColor(0.9)
w.setCameraPosition(distance=3)

l.addWidget(w, 0, 0, 1, 1)

sp = w.sizePolicy()
w.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding))

mw.show()

n_tri = 100000

vertices = np.random.uniform(size=(n_tri, 3, 3)).reshape((-1, 3))

indices = np.arange(vertices.shape[0]).reshape((-1, 3))

colors = np.random.uniform(size=(vertices.shape[0], 3))

m1 = gl.GLMeshItem(vertexes=vertices, faces=indices, vertexColors=colors, smooth=False,
                   drawEdges=False, drawFaces=True, edgeColor=(0, 1, 0, 1))

w.addItem(m1)

def update():

    vertices = np.random.uniform(size=(n_tri, 3, 3)).reshape((-1, 3))

    m1.setMeshData(vertexes=vertices, faces=indices, vertexColors=colors, smooth=False,
                   drawEdges=False, drawFaces=True, edgeColor=(0, 1, 0, 1))

t2 = QtCore.QTimer()
t2.timeout.connect(update)
t2.start(250)

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

0 个答案:

没有答案