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:

https://trinhngocthuyen.github.io/tech/method-swizzling-what-why-and-how/

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


--
_______________________________________________
lazarus mailing list
[email protected]
https://lists.lazarus-ide.org/listinfo/lazarus

Reply via email to