From kde-core-devel Fri Mar 13 16:51:11 2009 From: Hans Meine Date: Fri, 13 Mar 2009 16:51:11 +0000 To: kde-core-devel Subject: Re: KIO::PreviewJob pixmaps + Qt4.5 crashes Message-Id: <200903131751.13186.hans_meine () gmx ! net> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=123696316010846 On Friday 13 March 2009 15:14:33 Aleix Pol wrote: > > #3) The other response is likely right. I bet the following accesses > > deleted memory with the Raster engine: > > > > const int w = 16, h = 16; > > QRgb* data = new QRgb[w*h*4]; > > std::memset(data, 0, w*h*4); > > QImage* i = new QImage(data, w, h, QImage::Format_ARGB32_Premultiplied); > > QPixmap p = QPixmap::fromImage(*i); > > delete i; > > //Do stuff with p here > > > > There seems to be no deep copy going on here (and coincidentally, > > QImage::convertToFormat docs lie --- it doesn't always return a copy) > > Yes it is possible, but I don't know where this copy happens at all. Exactly, Maskim (and I) pointed out that there *is* no copy. AFAICS, it would be enough to detach the QImage, alas detach() is internal. How about QImage* i = new QImage((const QRgb *)data, w, h, QImage::Format_ARGB32_Premultiplied); (void)i.bits(); // detach from data if the above is the actual code? BTW: It probably works with OpenGL for you, because OpenGL is another client/server system, i.e. the data is copied into an OpenGL-managed area (possibly even the graphics card's memory). HTH, Hans