python - PySide crash when displaying pixmaps -


i programming gui application data visualization using python , qt via pyside. experience occasional crashes ('python.exe has stopped working') think narrowed down following problem:

when creating pixmap numpy array, somehow memory freed python (?) when pixmap exists. this not happen if image format used qimage.format_argb32. (why not?). check out code example below, hope can reproduce problem.


edit: clarify - if numpy array not deleted python, works expected. however, in application, new data generated , have find way track dataset displayed pixmap, , delete not displayed anymore. find correct way qt take care of (image-) data , store in memory until not required anymore.


as far understood documentation of qt , pyside, pixmap should hold data of image, qt should responsible memory management.

is bug in qt, pyside, or did not understand something? not find details on memory management in regular documentation.

background: need regularly update data display, may happen between creating pixmap , displaying it, numpy data array overwritten python (as there cpu intensive threads involved slow gui). thus, storing numpy array forever not option.

here code example, interesting bits happen in display_image method:

import numpy np pyside import qtcore, qtgui import sys  class displaywidget(qtgui.qwidget):     def __init__(self,parent = none):         super(displaywidget, self).__init__(parent)          ## set gui elements         self.setlayout(qtgui.qgridlayout())         self.view = qtgui.qgraphicsview()         self.layout().addwidget(self.view)                 self.scene = qtgui.qgraphicsscene()         self.view.setscene(self.scene)          # create pixmap , display on graphicsview         self.display_image()     def display_image(self):         # create image data in numpy array         size = 1024         r = np.linspace(0,255, num = size**2, dtype = np.uint32)         argb = (r<<16) +(255<<24)          # image should display black red shading         image = qtgui.qimage(argb, size,size, size*4, qtgui.qimage.format_rgb32)          ### using argb format option not cause problem #        image = qtgui.qimage(argb, size,size, size*4, qtgui.qimage.format_rgb32)          pixmap = qtgui.qpixmap.fromimage(image)          self.scene.addpixmap(pixmap)         ### when image data stored, works fine, #        self.cache = argb         ### if pixmap , image stored, problem still exists #       self.cache = [pixmap, image]    def main(argv):     ## create application , main window     try:         app = qtgui.qapplication(argv)         new_qtapp = true     except:         new_qtapp = false     mainwindow = qtgui.qmainwindow()     mainwindow.setcentralwidget(displaywidget())     mainwindow.show()     if new_qtapp:         sys.exit(app.exec_())     return mainwindow if __name__=="__main__":     w = main(sys.argv) 

i using 32 bit python 2.7.6 , pyside 1.2.2 on generic windows7 office pc.

thanks help!

this simple change keeps image being garbage collected when function done. seems caused problem

self.argb = (r<<16) +(255<<24)  # image should display black red shading image = qtgui.qimage(self.argb, size,size, size*4, qtgui.qimage.format_rgb32) 

enter image description here


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -