From 4e9cf8ac021cad517dccbac4528588d6f2ff453d Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 26 Feb 2020 15:56:51 -0800 Subject: [PATCH] Fir a deadlock when exiting on MacOS (GL backend) Closes #2159 There was two issues: 1) Fence::wait would return prematurely when the the timeout was set to WAIT_FOREVER. 2) (At least) when running from the command line, events were not read from the main queue. Instead we have to use NSRunLoop instead of NSApplication APIs. --- filament/backend/src/opengl/PlatformCocoaGL.mm | 8 +------- filament/src/Fence.cpp | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/filament/backend/src/opengl/PlatformCocoaGL.mm b/filament/backend/src/opengl/PlatformCocoaGL.mm index 42fb85da76..e93308e2fd 100644 --- a/filament/backend/src/opengl/PlatformCocoaGL.mm +++ b/filament/backend/src/opengl/PlatformCocoaGL.mm @@ -147,13 +147,7 @@ bool PlatformCocoaGL::pumpEvents() noexcept { if (![NSThread isMainThread]) { return false; } - while (true) { - NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; - if (event == nil) { - break; - } - [NSApp sendEvent:event]; - } + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantPast]]; return true; } diff --git a/filament/src/Fence.cpp b/filament/src/Fence.cpp index 93a6ebdaa1..4c2f41fb48 100644 --- a/filament/src/Fence.cpp +++ b/filament/src/Fence.cpp @@ -99,7 +99,7 @@ FenceStatus FFence::wait(Mode mode, uint64_t timeout) noexcept { } engine.pumpPlatformEvents(); const auto elapsed = std::chrono::system_clock::now() - startTime; - if (elapsed >= ns(timeout)) { + if (timeout != Fence::FENCE_WAIT_FOR_EVER && elapsed >= ns(timeout)) { break; } }