Chapter 4 playgrounds not compiling Xcode 12.0.1

I know the Forums have had some messages referring to Playgrounds as being buggy. When I try to run either the Starter or the Final playground code for Chapter 4, I get the following error message for line 20 of the main playground file: error: “Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
The process has been left at the point where it was interrupted, use “thread return -x” to return to the state before expression evaluation.”
The debugger window: " Fatal error: Unexpectedly found nil while unwrapping an Optional value: file N3DTransforms_Sources/Utility.swift, line 21"
Can you offer a suggestion?
Thank you.

Hi @rpitman, I’m also seeing this error as well on Xcode 12.0. It seems like the constant “path” is returning nil.

let path = Bundle.main.path(forResource: "Shaders.metal", ofType: "metal".

@mhorga, any ideas on how to resolve this issue?

1 Like

It appears Apple have just changed the way playgrounds access Metal shaders, as I was asked this yesterday too.

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 change the method in Utility.swift:

public func createLibrary() -> MTLLibrary {

Thank you, Caroline. You’re the most responsive author I’ve seen on any forum anywhere.


Thanks A lot @Caroline.