Prevent deadlock if working on non-main thread

This commit is contained in:
Pedro J. Estébanez 2024-04-23 19:30:04 +02:00
parent 756f00ae8f
commit a97ba52dbf

View File

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