Skip to content

Commit

Permalink
Merge pull request #12579 from de1acr0ix/fix-mainloop-cancellation-hang
Browse files Browse the repository at this point in the history
Fix UI thread main loop cancellation from another thread on macOS
  • Loading branch information
maxkatz6 authored Aug 18, 2023
2 parents c59e63e + f895661 commit 0b6294e
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions native/Avalonia.Native/src/OSX/platformthreading.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ virtual void Cancel() override
Cancelled = true;
if(Running)
{
Running = false;
if(![NSThread isMainThread])
{
AddRef();
Expand All @@ -28,22 +27,22 @@ virtual void Cancel() override
});
return;
};

Running = false;
if(IsApp)
[NSApp stop:nil];
else
{
// Wakeup the event loop
NSEvent* event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
location:NSMakePoint(0, 0)
modifierFlags:0
timestamp:0
windowNumber:0
context:nil
subtype:0
data1:0
data2:0];
[NSApp postEvent:event atStart:YES];
}

// Wakeup the event loop
NSEvent* event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
location:NSMakePoint(0, 0)
modifierFlags:0
timestamp:0
windowNumber:0
context:nil
subtype:0
data1:0
data2:0];
[NSApp postEvent:event atStart:YES];
}
};
};
Expand Down

0 comments on commit 0b6294e

Please sign in to comment.