Qt-interest Archive, September 2007
freeze in QPainterPath.united()
Message 1 in thread
Hi all,
can anyone explain why following code freezes? All it does is
create some painter paths and unite them together using
QPainterPath.united()
- it freezes only when united() is called from mouseReleaseEvent()
handler, not when it is called elsewhere, eg. in main()
- freeze happens also with QPainterPath.subtracted() and different
input
Am i doing something wrong?
I attach the source code and the simplest input that causes the error.
Any help appreciated.
Tomas
Here is a gdb backtrace:
#0 0xb786a709 in QPathClipper::clip () from /usr/lib/libQtGui.so.4
#1 0xb7867a2f in QPathClipper::clip () from /usr/lib/libQtGui.so.4
#2 0xb782c6ce in QPainterPath::united () from /usr/lib/libQtGui.so.4
#3 0x0804a8d4 in MyWidget::mouseReleaseEvent ()
#4 0xb77743fb in QWidget::event () from /usr/lib/libQtGui.so.4
#5 0xb7722af1 in QApplicationPrivate::notify_helper () from /usr/lib/libQtGui.so.4
#6 0xb77236cb in QApplication::notify () from /usr/lib/libQtGui.so.4
#7 0xb7e7b88e in QCoreApplication::notifyInternal () from /usr/lib/libQtCore.so.4
#8 0xb772df9b in QApplicationPrivate::QApplicationPrivate () from /usr/lib/libQtGui.so.4
#9 0xb778ea92 in QApplication::x11ProcessEvent () from /usr/lib/libQtGui.so.4
#10 0xb778c7aa in QApplication::x11ProcessEvent () from /usr/lib/libQtGui.so.4
#11 0xb77ba66e in QX11Info::copyX11Data () from /usr/lib/libQtGui.so.4
#12 0xb7239d6c in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#13 0xb723d19f in g_main_context_check () from /usr/lib/libglib-2.0.so.0
#14 0xb723d705 in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
#15 0xb7ea460c in QEventDispatcherGlib::processEvents () from /usr/lib/libQtCore.so.4
#16 0xb77b9f24 in QX11Info::copyX11Data () from /usr/lib/libQtGui.so.4
#17 0xb7e78816 in QEventLoop::processEvents () from /usr/lib/libQtCore.so.4
#18 0xb7e78998 in QEventLoop::exec () from /usr/lib/libQtCore.so.4
#19 0xb7e7bfdb in QCoreApplication::exec () from /usr/lib/libQtCore.so.4
#20 0xb7722674 in QApplication::exec () from /usr/lib/libQtGui.so.4
#21 0x0804a5f4 in main ()
#include <QApplication>
#include <QApplication>
#include <QMainWindow>
#include "qpp_w.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow mw;
mw.setCentralWidget(new MyWidget(&mw));
mw.show();
app.exec();
}
#include <QApplication>
#include <QApplication>
#include <QWidget>
#include <QPainterPath>
#include <cstdio>
class MyWidget : public QWidget {
Q_OBJECT
public:
MyWidget(QWidget *parent) : QWidget(parent) {}
protected:
void mouseReleaseEvent(QMouseEvent *event)
{
QPainterPath path;
QPainterPath newPath;
FILE *f = fopen("path", "r");
char line[256];
while (fgets(line, 255, f)) {
int x, y;
switch (line[0]) {
case 'm':
sscanf(line, "m %d, %d\n", &x, &y);
newPath.moveTo(x, y);
break;
case 'l':
sscanf(line, "l %d, %d\n", &x, &y);
newPath.lineTo(x, y);
break;
case 'u':
path = path.united(newPath);
newPath = QPainterPath();
break;
default:
printf("unknown command\n");
break;
}
printf(line);
}
fclose(f);
printf("end of input\n");
QApplication::exit(0);
}
};
m 1,20
m 1,20
l 30,30
l 10,20
l 10,30
u
m 1,10
l 1,20
l 30,30
u
Message 2 in thread
Tomáš Kazmar a écrit :
> Hi all,
>
> can anyone explain why following code freezes? All it does is
> create some painter paths and unite them together using
> QPainterPath.united()
>
> - it freezes only when united() is called from mouseReleaseEvent()
> handler, not when it is called elsewhere, eg. in main()
> - freeze happens also with QPainterPath.subtracted() and different
> input
>
> Am i doing something wrong?
>
> I attach the source code and the simplest input that causes the error.
I doesn't look like you're doing something wrong. In any case Qt shouldn't get
stuck in an endless loop. Qt enters an endless loop in QPathClipper::clip() in
file src/gui/painting/qpathclipper.cpp:
QPainterPath QPathClipper::clip(Operation op)
{
[...]
QList<PathVertex*> vertices;
while (not_over)
not_over = d->walkResultingPath(start, prev_code_owner,
current, [...]);
[...]
For some reason "not_over" remains true and Qt never gets out of this loop.
I suggest you send a bug report to Trolltech:
http://trolltech.com/bugreport-form
--
[ signature omitted ]