I have been working through the 3D Graphics with Metal video course and this issue (EXC_BAD_ACCESS(EXC_I386_GPFLT)) appears in all of the projects after the ArcballCamera class was introduced.
The solution above resolves the issue. I was just noting that it was present in the video course as well.
Have anyone else had trouble running the starter (or final) playground in Ch4?
It looks like itβs having trouble reading Shaders.metal from the bundle.
This is the error Iβm seeing:
**Fatal error: Unexpectedly found nil while unwrapping an Optional value: file N3DTransforms_Sources/Utility.swift, line 21**
Hi @cisforcojo - thanks for bringing this to our attention
It looks as if Apple have changed the way playgrounds access Metal shaders. You used to have to access it via the bundle, but it seems that we can now just use makeDefaultLibrary()
as we do in an app.
So:
public func createLibrary() -> MTLLibrary {
device.makeDefaultLibrary()!
}
Wow, thanks so much for the quick response!
Chapter 21 starter project.
Renderer.swift: vertexDescriptor
should be defined:
lazy var vertexDescriptor: MDLVertexDescriptor = {
let vertexDescriptor = MDLVertexDescriptor()
vertexDescriptor.attributes[0] =
MDLVertexAttribute(name: MDLVertexAttributePosition,
format: .float3,
offset: 0, bufferIndex: 0)
vertexDescriptor.attributes[1] =
MDLVertexAttribute(name: MDLVertexAttributeNormal,
format: .float3,
offset: 0, bufferIndex: 1)
vertexDescriptor.layouts[0] = MDLVertexBufferLayout(stride: MemoryLayout<float3>.stride)
vertexDescriptor.layouts[1] = MDLVertexBufferLayout(stride: MemoryLayout<float3>.stride)
return vertexDescriptor
}()
The normal vertex attribute was defined as a float2
, when it should be a float3
.