Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Metal MTLCreateSystemDefaultDevice returns nil

Tags:

ios

swift

metal

I try to develop something on Metal iOS and receive the following error:

Code:

let device = MTLCreateSystemDefaultDevice()!

Error:

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

I'm on xcode 9.4.1

iOS SDK: 11.4

Architecture: arm64 armv7 armv7s

Can someone please help.

like image 471
Keloo Avatar asked Jun 27 '18 13:06

Keloo


People also ask

Does SwiftUI require mtkview during initialization?

... SwiftUI calls this method before calling the makeUIView (context:) method. My Coordinator class is just a renderer of sorts, and during initialization requires an MTKView. This is where I am having trouble.

How do I change a texture from Swift to MetalKit?

The answer is pretty much everything in MetalTexture! To switch texture loading to MetalKit, delete MetalTexture.swift from your project. Again, this will cause some errors; you’ll fix these shortly. Next, add a parameter to the initializer. Find this line of code:

Why can’t I use SIMD and glkit in Swift?

When this tutorial series first started, there were issues in Swift that prevented you from using C data types like the ones found in the SIMD and GLKit frameworks. To overcome those issues, you ended up having to write an Objective-C wrapper to represent a 4×4 matrix and perform various GLKMath operations.

What is MetalKit and how does it work?

Apple presented MetalKit at WWDC 2015 as a gateway to Metal. The framework gives you utilities that reduce the amount of boilerplate code you have to write in order to get an app running on Metal. Texture loading: Allows you to easily load image assets into Metal textures using a MTKTextureLoader.


Video Answer


1 Answers

Test it on real device iPhone or iPad, it will not work on Simulator.

like image 154
aBilal17 Avatar answered Sep 18 '22 08:09

aBilal17