Recent

Author Topic: [Solved] Custom Control causes QTransform error  (Read 1371 times)

alanphys

  • Jr. Member
  • **
  • Posts: 56
[Solved] Custom Control causes QTransform error
« on: May 12, 2022, 11:30:55 am »
Hi

I recently upgraded to Lazarus 2.2.0. I have a custom control DTrackBar in one of my production apps which I have used for many years that is now giving a SIGSEGV error (runtime error 216) under QT5. Other applications that don't have this control run correctly. I am running Fedora 34 with QT version 5.15.2.

The control and app compiles and runs correctly under Windows and GTK2. The interesting thing is that the error only occurs once under QT5 after which the app and control work correctly. This, to me, indicates an initialisation problem. I have gone through the code of the control and as far as I can determine everything is being instantiated properly. It seems to me that on the first run the device context (Canvas) is getting lost somewhere.

A stack trace from a simple project containing only the control is included below:

I have:
Installed version 1.2.10 of Dave Bannon's libQt5Pas rpm package. (big thanks @dbannon)
Uninstalled this and installed the source and compiled from scratch (I've had previous issues with glibc).
Deleted this and reverted back to version 1.2.9 shipped with Lazarus 2.2.0. Compiled this from scratch again.

Both versions give the same error. The last working version of libQt5Pas was 1.2.6 from Lazarus 2.0.12.

I have stepped through the control code. Canvas.Draw is called with a valid bitmap and the Canvas appears to exist. I suspect that the control is not initialising something that was previously initialised by default.

If any of the QT5 gurus can shed some light or give me some pointers where to look I would be grateful.

Regards
Alan

Stack Trace
#0 SYSTEM_$$_HANDLEERRORADDRFRAME$LONGINT$POINTER$POINTER at :0
#1 QTransform::type() const at :0
#2 QRasterPaintEngine::drawImage(QRectF const&, QImage const&, QRectF const&, QFlags<Qt::ImageConversionFlag>) [clone .part.0] at :0
#3 QPainter::drawPixmap(QRectF const&, QPixmap const&, QRectF const&) at :0
#4 QPainter_drawPixmap11 at :0
#5 RENDERPIXMAP(0x7fffffffc110, 0xe7b130, 0x0, false) at qt5/qtwinapi.inc:6931
#6 STRETCHMASKBLT(0x7fffe5c1fd50, 140736935857984, 5, 15, 10, 20, 140736935859904, 0, 0, 10, 20, 0, 0, 0, 13369376) at qt5/qtwinapi.inc:7016
#7 STRETCHMASKBLT(140736935857984, 5, 15, 10, 20, 140736935859904, 0, 0, 10, 20, 0, 0, 0, 13369376) at include/lclintf.inc:457
#8 DRAW(0x7fffe5c779c0, 0x7fffe5be35c0, {LEFT = 5, TOP = 15, RIGHT = 15, BOTTOM = 35, TOPLEFT = {X = 5, Y = 15}, BOTTOMRIGHT = {X = 15, Y = 35}, VECTOR = {5, 15, 15, 35}}) at include/rasterimage.inc:245
#9 STRETCHDRAW(0x7fffe5be35c0, {LEFT = 5, TOP = 15, RIGHT = 15, BOTTOM = 35, TOPLEFT = {X = 5, Y = 15}, BOTTOMRIGHT = {X = 15, Y = 35}, VECTOR = {5, 15, 15, 35}}, 0x7fffe5c779c0) at include/canvas.inc:48
#10 DRAW(0x7fffe5be35c0, 5, 15, 0x7fffe5c779c0) at include/canvas.inc:26
#11 UPDATETHUMB(0x7fffe5c4cc70) at Tracker2.pas:797
#12 PAINT(0x7fffe5c4cc70) at Tracker2.pas:1157
#13 PAINTWINDOW(0x7fffe5c4cc70, 140736935857984) at include/customcontrol.inc:123
#14 PAINTHANDLER(0x7fffe5c4cc70, {MSG = 15, UNUSEDMSG = 0, DC = 140736935857984, PAINTSTRUCT = 0x7fffe5c70a20, RESULT = 0}) at include/wincontrol.inc:4857
#15 WMPAINT(0x7fffe5c4cc70, {MSG = 15, UNUSEDMSG = 0, DC = 140736935857984, PAINTSTRUCT = 0x7fffe5c70a20, RESULT = 0}) at include/wincontrol.inc:6836
#16 WMPAINT(0x7fffe5c4cc70, {MSG = 15, UNUSEDMSG = 0, DC = 140736935857984, PAINTSTRUCT = 0x7fffe5c70a20, RESULT = 0}) at include/customcontrol.inc:103
#17 SYSTEM$_$TOBJECT_$__$$_DISPATCH$formal at :0
#18 ?? at :0
#19 ?? at :0
#20 ?? at :0
#21 ?? at :0
#22 .Ld264 at :0
#23 VMT_$CONTROLS_$$_TGRAPHICCONTROL$indirect at :0
#24 ?? at :0
#25 ?? at :0
#26 ?? at :0
#27 ?? at :0
#28 ?? at :0
#29 WNDPROC(0x7fffe5c4cc70, {MSG = 15, UNUSEDMSG = 0, WPARAM = 140736935857984, LPARAM = 140737048414752, RESULT = 0}) at include/control.inc:2282
#30 WNDPROC(0x7fffe5c4cc70, {MSG = 15, UNUSEDMSG = 0, WPARAM = 140736935857984, LPARAM = 140737048414752, RESULT = 0}) at include/wincontrol.inc:5429
#31 SLOTPAINT(0x7fffdcd9c040, 0xe14260, 0x7fffffffcd70) at qt5/qtwidgets.pas:4263
#32 EVENTFILTER(0x7fffdcd9c040, 0xe14260, 0x7fffffffcd70) at qt5/qtwidgets.pas:2783
#33 EVENTFILTER(0x7fffdcd9c040, 0xe14260, 0x7fffffffcd70) at qt5/qtwidgets.pas:17033
#34 VIEWPORTEVENTFILTER(0x7fffdcdb9400, 0x7fffffffcd70, 0x7fffffffcc5f) at qt5/qtwidgets.pas:17551
#35 QLCLAbstractScrollArea::viewportEvent(QEvent*) at :0
#36 QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) at :0
#37 QApplicationPrivate::notify_helper(QObject*, QEvent*) at :0
#38 QCoreApplication::notifyInternal2(QObject*, QEvent*) at :0
#39 QWidgetPrivate::sendPaintEvent(QRegion const&) at :0
#40 QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) at :0
#41 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) at :0
#42 QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) at :0
#43 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) at :0
#44 QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) at :0
#45 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) at :0
#46 QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) at :0
#47 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) at :0
#48 QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, QFlags<QWidgetPrivate::DrawWidgetFlag>, QPainter*, QWidgetRepaintManager*) at :0
#49 QWidgetRepaintManager::paintAndFlush() at :0
#50 QWidgetRepaintManager::sync(QWidget*, QRegion const&) at :0
#51 QWidgetWindow::event(QEvent*) at :0
#52 QApplicationPrivate::notify_helper(QObject*, QEvent*) at :0
#53 QCoreApplication::notifyInternal2(QObject*, QEvent*) at :0
#54 QGuiApplicationPrivate::processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent*) at :0
#55 QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) at :0
#56 xcbSourceDispatch(_GSource*, int (*)(void*), void*) at :0
#57 g_main_context_dispatch at :0
#58 g_main_context_iterate.constprop at :0
#59 g_main_context_iteration at :0
#60 QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) at :0
#61 APPWAITMESSAGE(0x7fffe5c1fd50) at qt5/qtobject.inc:313
#62 IDLE(0x7fffe5c1f8f0, true) at include/application.inc:453
#63 HANDLEMESSAGE(0x7fffe5c1f8f0) at include/application.inc:1265
#64 RUNLOOP(0x7fffe5c1f8f0) at include/application.inc:1383
#65 APPRUN(0x7fffe5c1fd50, {Proc = {procedure (POINTER)} 0x7fffffffe210, Self = 0x7fffe5c1f8f0}) at qt5/qtobject.inc:292
#66 RUN(0x7fffe5c1f8f0) at include/application.inc:1371
#67 main at project1.lpr:23
« Last Edit: June 22, 2022, 02:45:56 pm by alanphys »
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

zeljko

  • Hero Member
  • *****
  • Posts: 1262
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Custom Control causes QTransform error
« Reply #1 on: May 12, 2022, 06:45:46 pm »
Does it work with Qt4 ?
EDIT: In your case it crashes inside Qt library. You should check somehow input params for drawPixmap() at line 6931 in qtwinapi.inc,
eg via writeln (X,Y,Width,Height) and try to save ATempPixmap into file before call to drawPixmap() to see if they're valid. Also, what is format of that image ?
« Last Edit: May 12, 2022, 06:52:38 pm by zeljko »

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Custom Control causes QTransform error
« Reply #2 on: May 13, 2022, 03:34:32 pm »
Thanks for the reply zeljko

I did as you suggested. The bitmap is constructed correctly and is valid (attached). The X,Y and Width,Height values are correct and valid. The device context has the correct handle.

I commented out the Canvas.Draw statement in the controls code and put a Canvas.TextOut and got a very similar error. So now I'm wondering if the device context is getting corrupted somewhere.

I can't test on QT4 as Fedora has dropped QT4 but this was working on QT5.

I will investigate further and see if I can isolate the problem. Thanks for the assistance so far.
Regards
Alan
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

zeljko

  • Hero Member
  • *****
  • Posts: 1262
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Custom Control causes QTransform error
« Reply #3 on: May 13, 2022, 07:41:40 pm »
I must see/test sample project to get any clue about problem. Lazarus and my projects works fine with Qt-5.15.ANY

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Custom Control causes QTransform error
« Reply #4 on: May 16, 2022, 08:51:25 am »
Update

So this is weird. Over the weekend I thought I would do some debugging. I started Lazarus and the project loaded, compiled and ran with no problems. I normally run my laptop with a second screen attached and I do most of my work on the larger external screen. This time I was using the laptop screen only. Further experimentation showed the test project runs correctly on the laptop screen but not on the external screen.

It seems the device context for the external screen is being corrupted in some way. I will see if I can isolate it. I have attached the source code of the component. It contains a sample project if you want to look at it.

Regards
Alan
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

zeljko

  • Hero Member
  • *****
  • Posts: 1262
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Custom Control causes QTransform error
« Reply #5 on: May 16, 2022, 09:46:21 am »
I don't see any attachment

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Custom Control causes QTransform error
« Reply #6 on: May 16, 2022, 10:00:16 am »
Sorry Zeljko

Component attached. But I have in the meantime got a minimal project to create the error. Open a new project and put the following code in the form's OnPaint event handler.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. var ABitmap    :TBitMap;
  3. begin
  4. ABitmap := TBitMap.Create;
  5. ABitmap.Width := 20;
  6. ABitmap.Height := 10;
  7. Canvas.Brush.Style := bsClear;
  8. Canvas.TextOut(5,5, 'Okay');
  9. ABitmap.Canvas.CopyRect(Rect(0,0,ABitmap.Width,ABitmap.Height),
  10.                         Canvas,
  11.                         Rect(5,5,5+ABitmap.Width,5+ABitMap.Height));
  12. Canvas.TextOut(250,120, 'Not Okay');
  13. end;

Compile and run with the form on the second (external) screen.

Regards
Alan
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

zeljko

  • Hero Member
  • *****
  • Posts: 1262
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Custom Control causes QTransform error
« Reply #7 on: May 16, 2022, 02:26:17 pm »
Can you add ABitmap.Free at the end ? I cannot test with 2 monitors atm, but will check

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Custom Control causes QTransform error
« Reply #8 on: May 17, 2022, 08:00:24 am »
Yes, sorry. Sloppy programming. Corrected procedure below.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. var ABitmap    :TBitMap;
  3. begin
  4. ABitmap := TBitMap.Create;
  5. ABitmap.Width := 20;
  6. ABitmap.Height := 10;
  7. Canvas.Brush.Style := bsClear;
  8. Canvas.TextOut(5,5, 'Okay');
  9. ABitmap.Canvas.CopyMode := cmSrcCopy;
  10. ABitmap.Canvas.CopyRect(Rect(0,0,ABitmap.Width,ABitmap.Height),
  11.                         Canvas,
  12.                         Rect(5,5,5+ABitmap.Width,5+ABitMap.Height));
  13. Canvas.TextOut(250,120, 'Not Okay');
  14. Abitmap.Free;
  15. end;

This still gives the problem. It appears to be caused by something in CopyRect but only appears later in TextOut.

Regards
Alan
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

zeljko

  • Hero Member
  • *****
  • Posts: 1262
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Custom Control causes QTransform error
« Reply #9 on: May 17, 2022, 09:19:55 am »
Can you test with trunk lazarus ?

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Custom Control causes QTransform error
« Reply #10 on: May 17, 2022, 03:54:57 pm »
Hi

Downloaded version: Lazarus 2.3.0 (rev main-2_3-1298-g174cf206d4) FPC 3.2.2 x86_64-linux-gtk2

Also recompiled libQt5Pas to version 1.2.10.

Still getting error.

Regards
Alan
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

zeljko

  • Hero Member
  • *****
  • Posts: 1262
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Custom Control causes QTransform error
« Reply #11 on: May 17, 2022, 05:03:18 pm »
One more info please: your "large" screen resultion and dpi ? Is it under wayland or x11 ? If it's wayland, please try x11 session just to isolate problem if possible.

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Custom Control causes QTransform error
« Reply #12 on: May 18, 2022, 08:46:29 am »
Both external and laptop screen are 1920x1080. They are driven by a NVIDIA RTX 3050 card with the proprietary NVIDIA drivers.

KDE is running on X11 still. As a matter of interest I opened up a GNOME session on Wayland. The results are the same. The demo project compiles and runs on GTK2 but not on QT5.

Is there a changelog for libQt5Pas anywhere?

Regards
Alan
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

zeljko

  • Hero Member
  • *****
  • Posts: 1262
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Custom Control causes QTransform error
« Reply #13 on: May 18, 2022, 12:57:23 pm »
Both external and laptop screen are 1920x1080. They are driven by a NVIDIA RTX 3050 card with the proprietary NVIDIA drivers.

KDE is running on X11 still. As a matter of interest I opened up a GNOME session on Wayland. The results are the same. The demo project compiles and runs on GTK2 but not on QT5.

Is there a changelog for libQt5Pas anywhere?

Regards
Alan

Good,  it's same as my laptop with 1920x1080 Nvidia GeForce GTX 1050 Ti Mobile, also I'm on 96dpi, LinuxMint 20.2 64bit. You can annotate Qt5Pas.pro and then jump to commits to see changes.

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Custom Control causes QTransform error
« Reply #14 on: May 27, 2022, 11:37:57 am »
Hi

I'm still working on this. I started by trying to revert the Qt5 commits but it was taking to long. I rolled back my system version to the last working version laz 2.0.12. The TrackBar test project loaded, compiled and ran OK. I then update my system lazarus to 2.2.0RC1 and the error appeared. The error does not appear to be in libQt5Pas as I was still on 1.2.6 and recompiling that to 1.2.9 did not change anything.

Is there any way of seeing which commits are included in each release? I tried looking for release dates in the git log but couldn't see any and the version release dates seem to be considerably later than the commit dates.

Regards
Alan
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

 

TinyPortal © 2005-2018