Errata for Metal by Tutorials, 2nd Edition

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.

@ericjenkinson - This should be fixed in the new Xcode beta - or does the post above help?

The solution above resolves the issue. I was just noting that it was present in the video course as well.

1 Like

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**

1 Like

Hi @cisforcojo - thanks for bringing this to our attention :slight_smile:

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()!
}
1 Like

Wow, thanks so much for the quick response!

1 Like

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.

1 Like