From f8956618790b80d178b04d36bcf9211273ca6c2e Mon Sep 17 00:00:00 2001 From: Hanjiang Yu Date: Fri, 18 Aug 2023 16:08:00 +0800 Subject: [PATCH] Fix main loop cancellation from another thread --- .../src/OSX/platformthreading.mm | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/native/Avalonia.Native/src/OSX/platformthreading.mm b/native/Avalonia.Native/src/OSX/platformthreading.mm index d80df68fea1..56b7ce97e03 100644 --- a/native/Avalonia.Native/src/OSX/platformthreading.mm +++ b/native/Avalonia.Native/src/OSX/platformthreading.mm @@ -17,7 +17,6 @@ virtual void Cancel() override Cancelled = true; if(Running) { - Running = false; if(![NSThread isMainThread]) { AddRef(); @@ -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]; } }; };