[Lazarus] Message Loop paused when no interaction with mouse?

Bernd prof7bit at googlemail.com
Wed Apr 20 11:26:30 CEST 2011


I am sure I have read some discussion about this already but I cannot
find it anymore, so I will ask here, I don't know whether it is a bug
or intentional and I am only using it wrongly. The following is what I
have and what I am trying to do:

* Linux (KDE3.5, windowmanager is kwin) Lazarus is latest SVN, LCL
widgetset is GTK+
* a TForm with a TImage
* a TThread (started when the form is created, running forever,
automatically drawing to the TImage)

The GUI thread is idle, the form is responsive, all the work is done
in the separate TThread. This thread will wait for RGB data from a
camera on a named pipe and read it and then write pixels in the TImage
via Image.Picture.Bitmap.RawImage.Data[somewhere]^ . It will call
Image.Picture.Bitmap.BeginUpdate before it starts and EndUpdate after
it is done and this is all working fine.

Exactly after each frame i can see there is the OnPictureChanged event
triggered, I can verify this with:

procedure TForm1.DisplayPictureChanged(Sender: TObject);
  writeln('\n*** frame ***');

It will print '*** frame ***'' three times a second, exactly the frame
rate of my camera. If I move the mouse around on the form I can see my
TImage updating at the same rate. I just have to move the mouse. As
soon as I stop moving the mouse over the form the TImage will not
update anymore. The events will still be fired, I can still see it
printing *** frame *** nicely every 300ms to the console, only the
TImage won't update.

I tried to call the Repaint method of the TImage (from within its
OnPictureChanged handler) but this will freeze it (infinite loop?), I
tried Image.Invalidate, I tried the same with the entire form, I tried
calling Application.HandleMessage (giving me GTK warnings about the
wrong thread (?) in the console), some things froze it, some crash it
and some have no effect at all.

I have also tried several things with Synchonize() and somehow managed
to freeze it but since I now already have my TImage firing its event
I figured out this would be the right place from where I should try to
update the GUI. But I can't find it.

Is this a bug or am I just missing something? The only way I have
found working is if I put  a timer onto the form and then only this:

procedure TForm1.Timer1Timer(Sender: TObject);

This empty event method is already enough to wake up the form and
"simulate" what I did with my mouse move. But I don't want to have a
timer firing every few milliseconds (it has to be really fast because
I can set my camera to much shorter exposure and higher frame rate),
this simply does not "look right" to me, I would rather have it call
the right method exactly after a new frame has arrived.

Since I cannot find anything with google relating to this I have
written this rather lengthy essay, hoping all possible search terms
are now included and the next one with this problem will find this

More information about the Lazarus mailing list