Chap 3 Resourses: MetalView.Swift seems to be hanging my mac

Hi there

I’ve has a disastrous 24 hours with my mac powerbook crashing.
I was revisiting Metal in the updated v3 book to integrate it with SwiftUI. Chapter 3 suggest loading the MetalView.Swift and dragging it to my project.

As soon as I did, my computer hung. Naturally I did not suspect this operation so I’ve done a ton of other things to fix it, freeing up memory, running the disk utility, etc. Each time I thought my computer was clear, I dragged the file again. Each time it hung. I went so far as reloading my operating system and re-downloading the metal materials from your site. Everything looked hunky dory until I dragged in your file. Then … disaster

Maybe the problem is something else but it seems to me after literally hours of work that I only hang when I drag your file. Could you please investigate?


That’s very frustrating for you. I don’t know quite what to suggest, as it works perfectly for me on my M1 Mac mini.

What device / operating system / Xcode version are you using?

Have you tried running the supplied final project? Does it work?

Instead of dragging the file in, what happens if you create a new Swift file in Xcode, open MetalView.swift in TextEdit, and copy the code from MetalView.swift to the new Swift file in Xcode?

1 Like

Hi Caroline

Macbook pro mid-21015
Monterey 12.6.3
Xcode Ver 14.2 (14C18)

I did try copying and pasting from GitHub and that failed too, in exactly the same way. What’s really puzzling is that all the crashes occur as soon as the file is created. There is no need to compile and run them. Strange!! (This is why I’m not sure your code is the problem but the only way I’ve managed to replicate it is to grab your code. I’m thinking of bringing it onto Penn & Teller Fool Us :grinning:)

I haven’t tried on the final project yet but I will when I get back to my desk.

I have however built my own version of MetalView (conforming to UIViewRepresentable) before I ever looked at your v3 book and it worked well and indeed it still works!!!


OK. My computer is cleaned up (RW metal materials binned) and working fine on all my own stuff.
I managed to make a copy of MetalView.Swift using copy|paste and it works.

But … even now … I can still replicate the problem as follows.

  1. download RW metal materials from GitHub
  2. simply click on MetalView.Swift in chapter 3 resources

Conclusion: there is something not nice in there.

Thank you Caroline for your very fast response.

I hope you are able to move forward from this. I still can’t replicate it after redownloading the source, but I am on a much newer M1 computer, with Ventura. (My computer has its own crashing problems too, but not this one.)

If anyone else reading this has this problem, or doesn’t have this problem, please post your experience. Thanks.

1 Like