PDA

View Full Version : paint device returned engine == 0, type: 3



MarkoSan
12th December 2007, 10:27
What does this debugger warning means????
paint device returned engine == 0, type: 3And I installed 4.3.3. Are there any bugs regarding qpainter, becuase SAME CODE worked on 4.3.2.???

high_flyer
12th December 2007, 10:34
becuase SAME CODE worked on 4.3.2.???
Is this a warning or an error?

marcel
12th December 2007, 10:40
Probably because you are trying to paint on a null QPaintDevice...
Can you post some code?

MarkoSan
12th December 2007, 10:41
I compiled same code under 4.3.3. and my app crashes. Then I went into debug mode with gdb and I get that warning (at runtime - after app crashes). And I do not have any clue what to do with it. I have been seeking error for 14 hours and I am desperate. :o:crying:

MarkoSan
12th December 2007, 10:43
Here is some code, I am "playing" with the code of "Cover browser demo". Here is code:
void CMerchandizeBrowser::drawItemAt(QPainter *p, const QPoint &loc,
const QImage &img,
qint16 w, qint16 h,
qint16 angle)
{
qDebug() << "Entered CMerchandizeBrowser::drawItemsAt ..."; // debug
Q_ASSERT(p!=0);
p->save();
qDebug() << "After first p->save()"; // debug
if (!m_MirrorCache.contains(img.cacheKey())) {
QImage mirror=mirrorImage(img);
m_MirrorCache.insert(img.cacheKey(), mirror);
}

QPointF pt(-img.height()/2, -img.height()/2);
QTransform trans;
trans.scale(qreal(w)/img.width(), qreal(h)/img.height());
trans.rotate(angle, Qt::YAxis);
p->setTransform(trans * QTransform().translate(loc.x(), loc.y()), true);

const QImage &mirror=m_MirrorCache[img.cacheKey()];
QPointF pt2(pt.x(), img.height()/2);
p->save();
qDebug() << "After second p->save()"; // debug
Q_ASSERT(p!=0);
p->setCompositionMode(QPainter::CompositionMode_Sourc e);
p->drawImage(pt2, mirror);
p->restore();

p->drawImage(pt, img);

p->restore();
qDebug() << "Exiting CMerchandizeBrowser::drawItemsAt ..."; // debug
}That warning is written only ONCE and "After first p->save()". And under 4.3.2 this exact code worked perfectly.

marcel
12th December 2007, 10:44
Chill dude...
Post some code and someone will figure it out :)

marcel
12th December 2007, 10:46
On what paint device did you use the painter passed to the function before entering this function? Maybe that paint device has been deallocated.

MarkoSan
12th December 2007, 10:51
The warning is laucnhed after call DrawItem at from:
void CMerchandizeBrowser::drawItemsBeforeSelected(QPain ter *p)
{
qDebug() << "Entered CMerchandizeBrowser::drawItemsBeforeSelected ..."; // debug
Q_ASSERT(p!=0);
QPoint selPt(width()/2-m_ImagesList[m_iSelected].width()/2,
height()/2-m_ImagesList[m_iSelected].height()/4);
qint16 widthDiff = selPt.x();
qint16 startIdx = m_iSelected - widthDiff/pos_diff;

if (startIdx < 0)
startIdx = 0;

for (qint16 i = 0, idx = startIdx; idx < m_iSelected; ++i, ++idx) {
const QImage &img = m_ImagesList[idx];

drawItemAt(p, QPoint(selPt.x()-(m_iSelected-i)*pos_diff, selPt.y()),
img, img.width() -size_diff, img.height()-size_diff, -55);
}
qDebug() << "Exiting CMerchandizeBrowser::drawItemsBeforeSelected ..."; // debug
}

jpn
12th December 2007, 10:57
Where is the QPainter object originally created? Where does CMerchandizeBrowser::drawItemsBeforeSelected() get called from?

MarkoSan
12th December 2007, 11:00
I think painter is created here, in line 4:
void CMerchandizeBrowser::paintEvent(QPaintEvent *e)
{
qDebug() << "Entered CMerchandizeBrowser::paintEvent ..."; // debug
QPainter p(this);
p.setClipRect(e->rect());
p.fillRect(rect(), Qt::black);
p.setRenderHint(QPainter::Antialiasing);
p.setRenderHint(QPainter::SmoothPixmapTransform);
#ifdef SCALE_VIEW
static qint16 diff = 0;
qint16 w = width() - diff;
qint16 h = height() - diff;
QTransform trans;
trans.translate(width()/2, height()/2);
trans.scale(qreal(w)/width(), qreal(h)/height());
trans.translate(-width()/2, -height()/2);
p.setTransform(trans);
#endif
drawItemsBeforeSelected(&p);
drawItemsAfterSelected(&p);
drawSelectedItem(&p);
#ifdef SCALE_VIEW
static bool goingUp = true;
if (goingUp)
diff += 3;
else
diff -= 3;
if (diff >= 200 || diff <= 0)
goingUp = !goingUp;
#endif
if (m_iSelected>=m_ImagesList.count())
m_iSelected=0;
//QTimer::singleShot(1000/60, this, SLOT(update()));
QTimer::singleShot(100/60, this, SLOT(update()));
qDebug() << "Exiting CMerchandizeBrowser::paintEvent ..."; // debug
}

high_flyer
12th December 2007, 11:09
You say the app is crashing, do you know where?

jpn
12th December 2007, 11:16
void CMerchandizeBrowser::paintEvent(QPaintEvent *e)
{
QPainter p(this);
[...]
//QTimer::singleShot(1000/60, this, SLOT(update()));
QTimer::singleShot(100/60, this, SLOT(update()));
}


Creation of QPainter looks look to me. But I hope you're aware that

100/60 = 1
1000/60 = 16

so you're attempting to schedule a paint event every one or every 16th millisecond. Of course, the platform won't succeed in delivering timer events at so tight interval and Qt will also optimize it a bit behind the curtains by merging pending paint events but it might still not be a wise thing to do.

MarkoSan
12th December 2007, 11:24
But this code, even with short timer, worked fine in 4.3.2. I simply do not get it. Let me try to change this timer.

Same warning!:crying:

wysota
12th December 2007, 11:40
That doesn't mean anything. I suggest you use a debugger to find out where the crash occurs instead of shooting blind.

MarkoSan
12th December 2007, 11:42
Ok, let me dig into debugger ... just to be sure where ...

Oh, my god!!!!!!!!!!!!!!

I've seen after 15 hours of debugging :D that extension of pictures are wrong. I had .png instead of .jpg. :D Now I have just one problem. Same picture is shown twice in the llne of pictures. Why is that??