[Lazarus] Modal Window Crashes on Mac OS X 10.15 Beta (Catalina)

Zoë Peterson zoe at scootersoftware.com
Wed Jun 12 17:48:33 CEST 2019

On 6/11/2019 11:56 PM, Dmitry Boyarintsev via lazarus wrote:
>     If it's a problem to check isRunning every time through
>     nextEventMatchingMask, and alternative with the same behavior would be
>     to swizzle in the runloop variant before calling inherited run and
>     switching it back once we get into it.
> Switching back? how is it possible?

"Swizzling" is the name for replacing the Objective C method pointers 
using method_exchangeImplementations.  It's not the same as overriding it.

There's a writeup of it here:


So, rather than overriding nextEventMatchingMask directly, ours is 
called something like runLoop_nextEventMatchingMask. 
TCocoaWidgetSet.AppRun swaps the function pointers, soour version is 
only called after we get to that point, and when we get into that 
function, we swap them back and call the original implementation like 
normal.  Our version only gets called once.

> We cannot be sure at what particular event, the hijacking would occur.
> Today, there was a bug report, about crash in the hijacking approach
> https://forum.lazarus.freepascal.org/index.php/topic,44930.msg323420.html#msg323420 
> The application written caused nextEventMatchMask to be called even 
> prior to Application.Init.

The above approach takes care of that, since our version is never used 
until we actually swap the method pointers.  It removes the need to 
maintain an "isRun" variable too.

Zoë Peterson
Scooter Software

More information about the lazarus mailing list