Hi Lazarus guru's,

I have stumbled into a problem with a Lazarus application. At random times, from 5 minutes to several hours, it crashes suddenly, and silently.
The only way to get a clue has been to run it with gdb.

It turns out that the crash occurs because of a Segmentation Fault in QTextEngine, triggered by a PostMessage, but apparently the cause was an endless loop in a previous PostMessage, which was executed some 1723 times. Attached the gdb stack trace (with 1722 identical items suppressed).

The scenario is a main thread using LCL, which is used, among other things not relevant here, to display information to the user, and another thread which communicates with a real-time process, and uses a PostMessage to wake up the main thread and make it show what required.

It appears that in some circumstances, the Application.ProcessMessages invoked in the main thread restarts the handling of the same message, thus creating and endless loop.

Is Application.ProcessMessages the vilain, or PostMessage or what?

Snippet of auxiliary thread code:


procedure TSendRec.DoDisplayError;
var
  Box: integer;
begin
   ErrList[ErrPut] := ErrMsg;
   inc(ErrPut);
   if ErrPut > High(ErrList) then ErrPut := 0;
   {$IFDEF USE_MESSAGES}
   PostMessage(Form1.Handle,LM_ERROR,Integer(ErrPut),0);
   {$ENDIF}
end;

Snippet of main thread code:

procedure TForm1.HandleError(var Msg: TLMessage);
var
.....
begin
  inc(ErrorCnt);
  if ErrGet <> ErrPut then begin
    ErrMsg := ErrList[ErrGet];
.......
    AnswerString := Format('UNIT %XH device %s ERROR
%XH',[ErrMsg.yunit,Localize(NamUn[ErrMsg.device]),ErrMsg.ytype]);
    ShowError(Self,Answerstring,BoxError[Box],Box);
    inc(ErrGet);
    if ErrGet > High(ErrList) then ErrGet := 0;
    end;
end;

procedure TForm1.ShowError(Sender: TObject; errorstring: string;
Berror: TBoxerror; ErrBox: Integer);
var
.......
begin
..... (code to fill up Panel4)
  Panel4.Show;
  Panel4.BringToFront;
  Application.ProcessMessages;
  ResetBtn.SetFocus;
end;

Thanks for any help

Giuliano


[Thread debugging using libthread_db enabled]
[New Thread 0x7fffe7a90700 (LWP 4310)]

Program received signal SIGSEGV, Segmentation fault.
0x0000003d6a7dc904 in QTextEngine::itemize() const () from /usr/lib64/libQtGui.so.4
#0  0x0000003d6a7dc904 in QTextEngine::itemize() const () from /usr/lib64/libQtGui.so.4
#1  0x0000003d6a6f1fc9 in QPainter::drawText(QPointF const&, QString const&, int, int) () from /usr/lib64/libQtGui.so.4
#2  0x00007ffff7d297db in drawText (handle=0x1729710, x=10, y=33, s=0x7fffff805578) at /usr/include/QtGui/qpainter.h:916
#3  QPainter_drawText3 (handle=0x1729710, x=10, y=33, s=0x7fffff805578) at src/qpainter_c.cpp:865
#4  0x0000000000751061 in DRAWTEXT (this=0x7fffe9ca2300, X=10, Y=33, S=0x7fffff805578) at qt/qtobjects.pas:2832
#5  0x00000000006d190d in EXTTEXTOUT (this=0x7ffff48d5730, DC=140737115726592, X=10, Y=20, OPTIONS=0, RECT=0x0, STR=0x7fffe9ca7990 '1 Â'#150, COUNT=4, DX=0x0) at qt/qtwinapi.inc:2291
#6  0x0000000000595551 in EXTUTF8OUT (this=0x7ffff48d5730, DC=140737115726592, X=10, Y=20, OPTIONS=0, RECT=0x0, STR=0x7fffe9ca7990 '1 Â'#150, COUNT=4, DX=0x0) at include/intfbaselcl.inc:214
#7  0x000000000057e41c in EXTUTF8OUT (DC=140737115726592, X=10, Y=20, OPTIONS=0, RECT=0x0, STR=0x7fffe9ca7990 '1 Â'#150, COUNT=4, DX=0x0) at include/lclintf.inc:147
#8  0x00000000005c2890 in TEXTOUT (this=0x7fffea0eed80, X=10, Y=20, TEXT=0x7fffe9ca7990 '1 Â'#150) at include/canvas.inc:1360
#9  0x00000000004e6fec in POSWRT (PIMAGE=33286, SYM=144 #144, BGCOL=0, FGCOL=65280, CANVAS=0x7fffea0eed80, POS=...) at USequen.pas:547
#10 0x00000000004e7b8b in DISPLCOD (DEVICE=FEEDER1_DEV, DISPLCORR=false, B=...) at USequen.pas:761
#11 0x00000000004fca93 in HANDLEMESSAGE (this=0x7ffff48d7790, MSG=...) at USequen.pas:5779
#12 0x00000000004b47a1 in SYSTEM_TOBJECT_$__DISPATCH$formal ()
#13 0x00000000004fc128 in ?? ()
#14 0x00007ffff48d7790 in ?? ()
#15 0x0000000000000003 in ?? ()
#16 0x0000000000000465 in ?? ()
#17 0x00007fffff8062e8 in ?? ()
#18 0x00007ffff48d7790 in ?? ()
#19 0x0000000000000001 in ?? ()
#20 0x00007fffe009ac60 in ?? ()
#21 0x00007fffe009ac60 in ?? ()
#22 0x0000000000d645d4 in ?? ()
#23 0x0000000000e5ad10 in ?? ()
-----------
The following section repeated 1723 times:
#24 0x0000000000602c6f in WNDPROC (this=0x7ffff48d7790, THEMESSAGE=...) at include/control.inc:2112
#25 0x00000000005f3dc4 in WNDPROC (this=0x7ffff48d7790, MESSAGE=...) at include/wincontrol.inc:5341
#26 0x00000000004d1afe in WNDPROC (this=0x7ffff48d7790, THEMESSAGE=...) at include/customform.inc:1443
#27 0x000000000072918d in DELIVERMESSAGE (this=0x7fffec014630, MSG=0, AISINPUTEVENT=false) at qt/qtwidgets.pas:5549
#28 0x0000000000726cfc in SLOTLCLMESSAGE (this=0x7fffec014630, SENDER=0xe5ad10, EVENT=0x7fffe009ac60) at qt/qtwidgets.pas:4353
#29 0x00000000007232c8 in EVENTFILTER (this=0x7fffec014630, SENDER=0xe5ad10, EVENT=0x7fffe009ac60) at qt/qtwidgets.pas:2678
#30 0x000000000072d364 in EVENTFILTER (this=0x7fffec014630, SENDER=0xe5ad10, EVENT=0x7fffe009ac60) at qt/qtwidgets.pas:7122
#31 0x0000003d67157127 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /usr/lib64/libQtCore.so.4
#32 0x0000003d6a5aa9dc in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQtGui.so.4
#33 0x0000003d6a5b094b in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQtGui.so.4
#34 0x0000003d67157d0c in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/libQtCore.so.4
#35 0x0000003d67158a57 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib64/libQtCore.so.4
#36 0x0000003d6717dad3 in ?? () from /usr/lib64/libQtCore.so.4
#37 0x0000003d5e440642 in g_main_context_dispatch () from /lib64/libglib-2.0.so.0
#38 0x0000003d5e444c98 in ?? () from /lib64/libglib-2.0.so.0
#39 0x0000003d5e444e4c in g_main_context_iteration () from /lib64/libglib-2.0.so.0
#40 0x0000003d6717d613 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/libQtCore.so.4
#41 0x0000003d6a649b5e in ?? () from /usr/lib64/libQtGui.so.4
#42 0x0000003d67158e6f in QCoreApplication::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/libQtCore.so.4
#43 0x00007ffff7d0273f in QCoreApplication_processEvents (flags=<value optimized out>) at src/qcoreapplication_c.cpp:105
#44 0x00000000006c7bc6 in APPPROCESSMESSAGES (this=0x7ffff48d5730) at qt/qtobject.inc:312
#45 0x00000000004dcf71 in PROCESSMESSAGES (this=0x7ffff48d5310) at include/application.inc:381
#46 0x00000000004fada4 in SHOWERROR (this=0x7ffff48d7790, SENDER=0x7ffff48d7790, ERRORSTRING=0x7fffe9badb30 'UNIT 40H device EYE ERROR 83H', BERROR=..., ERRBOX=0) at USequen.pas:5398
#47 0x00000000004fd23f in HANDLEERROR (this=0x7ffff48d7790, MSG=...) at USequen.pas:5888
#48 0x00000000004b47a1 in SYSTEM_TOBJECT_$__DISPATCH$formal ()
#49 0x00000000004fce90 in ?? ()
#50 0x00007ffff48d7790 in ?? ()
#51 0x0000000000000003 in ?? ()
#52 0x0000000000000466 in ?? ()
#53 0x00007fffff8075d8 in ?? ()
#54 0x00007ffff48d7790 in ?? ()
#55 0x0000000000000001 in ?? ()
#56 0x00007fffe009aba0 in ?? ()
#57 0x00007fffe009aba0 in ?? ()
#58 0x0000000000d645d4 in ?? ()
#59 0x0000000000e5ad10 in ?? ()
----------
#62052 0x0000000000602c6f in WNDPROC (this=0x7ffff48d7790, THEMESSAGE=...) at include/control.inc:2112
#62053 0x00000000005f3dc4 in WNDPROC (this=0x7ffff48d7790, MESSAGE=...) at include/wincontrol.inc:5341
#62054 0x00000000004d1afe in WNDPROC (this=0x7ffff48d7790, THEMESSAGE=...) at include/customform.inc:1443
#62055 0x000000000072918d in DELIVERMESSAGE (this=0x7fffec014630, MSG=0, AISINPUTEVENT=false) at qt/qtwidgets.pas:5549
#62056 0x0000000000726cfc in SLOTLCLMESSAGE (this=0x7fffec014630, SENDER=0xe5ad10, EVENT=0x7fffe0010bc0) at qt/qtwidgets.pas:4353
#62057 0x00000000007232c8 in EVENTFILTER (this=0x7fffec014630, SENDER=0xe5ad10, EVENT=0x7fffe0010bc0) at qt/qtwidgets.pas:2678
#62058 0x000000000072d364 in EVENTFILTER (this=0x7fffec014630, SENDER=0xe5ad10, EVENT=0x7fffe0010bc0) at qt/qtwidgets.pas:7122
#62059 0x0000003d67157127 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /usr/lib64/libQtCore.so.4
#62060 0x0000003d6a5aa9dc in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQtGui.so.4
#62061 0x0000003d6a5b094b in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQtGui.so.4
#62062 0x0000003d67157d0c in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/libQtCore.so.4
#62063 0x0000003d67158a57 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib64/libQtCore.so.4
#62064 0x0000003d6717dad3 in ?? () from /usr/lib64/libQtCore.so.4
#62065 0x0000003d5e440642 in g_main_context_dispatch () from /lib64/libglib-2.0.so.0
#62066 0x0000003d5e444c98 in ?? () from /lib64/libglib-2.0.so.0
#62067 0x0000003d5e444e4c in g_main_context_iteration () from /lib64/libglib-2.0.so.0
#62068 0x0000003d6717d613 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/libQtCore.so.4
#62069 0x0000003d6a649b5e in ?? () from /usr/lib64/libQtGui.so.4
#62070 0x0000003d67158e6f in QCoreApplication::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib64/libQtCore.so.4
#62071 0x00007ffff7d0273f in QCoreApplication_processEvents (flags=<value optimized out>) at src/qcoreapplication_c.cpp:105
#62072 0x00000000006c7bae in APPWAITMESSAGE (this=0x7ffff48d5730) at qt/qtobject.inc:300
#62073 0x00000000004dd050 in IDLE (this=0x7ffff48d5310, WAIT=true) at include/application.inc:413
#62074 0x00000000004e046a in HANDLEMESSAGE (this=0x7ffff48d5310) at include/application.inc:1266
#62075 0x00000000004e0959 in RUNLOOP (this=0x7ffff48d5310) at include/application.inc:1400
#62076 0x00000000006c7b96 in APPRUN (this=0x7ffff48d5730, ALOOP=...) at qt/qtobject.inc:283
#62077 0x00000000004e0901 in RUN (this=0x7ffff48d5310) at include/application.inc:1388
#62078 0x00000000004a4630 in main () at TreUp.lpr:41

A debugging session is active.

	Inferior 1 [process 4290] will be killed.

Quit anyway? (y or n) [answered Y; input not from terminal]


--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to