Recent

Author Topic: PeekMessage in GTK2  (Read 983 times)

CanineQwer

  • New Member
  • *
  • Posts: 18
Re: PeekMessage in GTK2
« Reply #15 on: July 22, 2020, 02:03:21 am »
Okay, if you ignoring me and dumping all errors on Glib, then I decided to find and fix the error myself.
Everything turned out to be simple.
Error in function:
Code: Pascal  [Select][+][-]
  1. procedure TGtkMessageQueue.Lock;
  2. begin
  3.   if InterlockedIncrement(fLock)=1 then
  4.     {$IFDEF USE_GTK_MAIN_OLD_ITERATION}
  5.     EnterCriticalsection(FCritSec);
  6.     {$ELSE}
  7.     g_main_context_acquire(FMainContext);
  8.         {$ENDIF}
  9. end;
  10.  
The fact is that, according to the documentation, the g_main_context_acquire function returns a boolean variable(bool) indicating the success of the function.
Those. an attempt to make g_main_context_acquire (in fact Lock) may fail.
Your code doesn't account for this.
Need to do:
Code: Pascal  [Select][+][-]
  1. procedure TGtkMessageQueue.Lock;
  2. var
  3.   b: Boolean;
  4. begin
  5.   if InterlockedIncrement(fLock)=1 then
  6.     {$IFDEF USE_GTK_MAIN_OLD_ITERATION}
  7.     EnterCriticalsection(FCritSec);
  8.     {$ELSE}
  9.     repeat
  10.       b := g_main_context_acquire(FMainContext);
  11.           //You can insert Sleep or something like that, but not required.
  12.     until(b);
  13.         {$ENDIF}
  14. end;
  15.  
I.e. we "lock" in a loop, until the lock is triggered.
I ask you to change this the next version.

 

TinyPortal © 2005-2018