glfw: CAMetalLayer not set despite call to glfwCreateWindowSurface
On macOS Mojave the surface creation failes with this error:
[***MoltenVK ERROR***] VK_ERROR_INITIALIZATION_FAILED: On-screen rendering requires a view that is backed by a layer of type CAMetalLayer.
The error happens when I call glfwCreateWindowSurface()
However my code works on macOS High Sierra, but not on Mojave.
Some information: macOS 10.14 Mojave MacBook 12" early 2016 GLFW: latest (master branch) LunarG SDK: 1.1.82.1
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 16 (5 by maintainers)
Commits related to this issue
- Cocoa: Apply retina window hint to Metal layer Related to #1340. — committed to glfw/glfw by elmindreda 5 years ago
- Cocoa: Explicitly set layer on surface creation Implicitly setting the layer doesn't work when there is already a layer. Our view is now layer-hosting for Vulkan. Fixes #1340. — committed to m4ce-w1ndu/glfw by elmindreda 5 years ago
- Cocoa: Apply retina window hint to Metal layer Related to #1340. — committed to m4ce-w1ndu/glfw by elmindreda 5 years ago
I ran into the same problems using VulkanSDK 1.1.92.1 and GLFW master. However I apparently fixed it by adding the following line
[window->ns.view setLayer:window->ns.layer];right beforecocoa_window.m:[window->ns.view setWantsLayer:YES];.Without this simple assignment, the layer was of type
_NSViewBackingLayeras I figured out usingNSLog(@"yourObject is a: %@", NSStringFromClass([window->ns.layer class]));.It seems that the surface ends up with the wrong dimensions this way 😦 I was able to fix that by removing (commenting out)
[window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]];which was added for #1229.Furthermore I have to use VulkanSDK 1.1.73.0 beacause
vkCreateSwapchainKHRstopped working. (I did not test any releases between those two mentioned.) Probably doing something terribly wrong, but I have no Idea what…Anyway this works for me and as I know almost nothing about Apple’s API I’m happy about that…
PS: The MoltenVK code to check for
CAMetalLayercan be found here.I believe this issue should be fixed now with e108c0de0d531123b560931c07c5a226e7d7a3da and so closed this issue for the 3.3 release, but please re-open or comment if that’s not the case. I never managed to reproduce it but it is clearly a bug judging by the discussion above and I want it to be fixed.
I haven’t tested this with the macOS 10.14.1 update and the current Vulkan SDK. I’ll check it and report back.
Atleast I can verify that on two devices with Mojave installed my Application using GLFW doesn’t work anymore because of this message in the error log.
It seems that Mojave does now require a CAMetalLayer just like iOS, instead of just a NSView.
I suggest you postpone the upgrade until a fix is released. Or try one of those suggested fixes from your link.