Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS event queue won't wakeup under certain circumstances #89

Open
martincapello opened this issue May 30, 2024 · 0 comments · May be fixed by #92
Open

macOS event queue won't wakeup under certain circumstances #89

martincapello opened this issue May 30, 2024 · 0 comments · May be fixed by #92
Assignees

Comments

@martincapello
Copy link
Member

martincapello commented May 30, 2024

I've found that when a laf client calls os::queue_event(ev) on macOS there is a chance that the event is not processed until some other OS event "wakes up" the queue. This can be seen when the getEvent() method is called from the main thread without a timeout, because when using a timeout, the timeout wakes up the queue and the issue is not perceived.

The issue can happen when the os::queue_event(ev) call takes place after line 77 and before line 82 in the following fragment of code:

if (!m_events.try_pop(ev)) {
if (timeout == kWithoutTimeout)
EV_TRACE("EV: Waiting for events\n");
// Wait until there is a Cocoa event in queue
m_sleeping = true;
event = [app nextEventMatchingMask:NSEventMaskAny
untilDate:untilDate
inMode:NSDefaultRunLoopMode
dequeue:YES];

Because the m_sleeping flag is still false in that moment, the queueEvent() method won't call the wakeUpQueue() method. Then the event got queued (in m_events queue) but then the queue will go to sleep (call to nextEventMatchingMask with untilDate=distantFuture because we are not using a timeout), waiting for any OS event to wake it up.

I think I've a fix for this which is basically a different approach, I'll try it with Aseprite and then create a PR.

EDIT: I've been trying this for a bit with Aseprite and it seems to work fine. Also I want to clarify why I need this fix:
While developing our laf based UI library I wanted to let the main thread just read all the OS events and if there is no OS events then just wait for the next one, no timeout, just sit and wait. When an OS event is available I just translate it to an app event and then push it to the app event queue. This is because in a background thread I keep reading the app queue to then send app events to the appropriate widgets. Still lots of work to do, but I just wanted to let you know which was the use case made the current implementation fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant