From 9e3bbc70ef6bd383435bf8d46165050a87f05d55 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Fri, 9 Oct 2009 15:50:16 +0200 Subject: Fixed bug where calling fill on pixmap with active painter would crash. Calling QPixmap::fill() on a pixmap may in some cases cause the painter's paint engine pointer to become stale. A subsequent call to the painter would therefore crash. Now, QPixmap::fill() will print a warning and return in those cases. I also added a warning in the documentation of QPixmap::fill(). Task-number: QTBUG-2832 Reviewed-by: Trond --- src/gui/image/qpixmap.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 558ae54..8133cc0 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -947,6 +947,9 @@ bool QPixmap::doImageIO(QImageWriter *writer, int quality) const /*! Fills the pixmap with the given \a color. + The effect of this function is undefined when the pixmap is + being painted on. + \sa {QPixmap#Pixmap Transformations}{Pixmap Transformations} */ @@ -955,6 +958,13 @@ void QPixmap::fill(const QColor &color) if (isNull()) return; + // Some people are probably already calling fill while a painter is active, so to not break + // their programs, only print a warning and return when the fill operation could cause a crash. + if (paintingActive() && (color.alpha() != 255) && !hasAlphaChannel()) { + qWarning("QPixmap::fill: Cannot fill while pixmap is being painted on"); + return; + } + detach(); data->fill(color); } -- cgit v0.12