Merge pull request #2214 from RandomShaper/avoid_deadlock

Prevent deadlock if working on non-main thread
This commit is contained in:
Bill Hollings 2024-04-23 17:17:18 -04:00 committed by GitHub
commit 19ad6b6cbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -615,9 +615,12 @@ void MVKSwapchain::initSurfaceImages(const VkSwapchainCreateInfoKHR* pCreateInfo
if (mtlLayer) { if (mtlLayer) {
NSString* screenName = @"Main Screen"; NSString* screenName = @"Main Screen";
#if MVK_MACOS && !MVK_MACCAT #if MVK_MACOS && !MVK_MACCAT
auto* screen = mtlLayer.screenMVK; // To prevent deadlocks, avoid dispatching screenMVK to the main thread at the cost of a less informative log.
if ([screen respondsToSelector:@selector(localizedName)]) { if (NSThread.isMainThread) {
screenName = screen.localizedName; auto* screen = mtlLayer.screenMVK;
if ([screen respondsToSelector:@selector(localizedName)]) {
screenName = screen.localizedName;
}
} }
#endif #endif
MVKLogInfo("Created %d swapchain images with size (%d, %d) and contents scale %.1f in layer %s (%p) on screen %s.", MVKLogInfo("Created %d swapchain images with size (%d, %d) and contents scale %.1f in layer %s (%p) on screen %s.",