Details
-
Bug
-
Resolution: Cannot Reproduce
-
Not Evaluated
-
None
-
1.1.2
-
None
Description
QImage.bits() returns a buffer object (yay!) which I would like to use for qimage2ndarray. However, the lifetime of the QImage is not bound to the buffer, i.e. the buffer does not hold a reference to it.
That means that it is easy to produce a crash, e.g. like this:
In [1]: filename = ...
In [2]: from PySide import QtGui
In [3]: image = QtGui.QImage(filename)
In [4]: isinstance(image.bits(), buffer)
Out[4]: True
In [5]: import numpy
In [6]: a = numpy.ndarray((image.height(), image.width()), numpy.uint32, image.bits(), 0, (image.bytesPerLine(), image.depth() / 8), 'C')
In [7]: numpy.all(a[:] > 0)
Out[7]: True
In [8]: del image
In [9]: a[:]
zsh: segmentation fault (core dumped) python =ipython
(I am attaching the input lines as .py file, too.)