[Chapter 4] Unable to run the sample code in the "Vertex Descriptors" Section

I copied the sample code from the chapter, but I can’t run it after compiling and it throws an error:
2023-05-16 23:39:01.594053+0800 Vertex[8589:409883] *** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: Remarks)

At the same time, I also tried to use the final version project in github and got the same error

I tried to add some break point in the code and I find it couldn’t create the MTLRenderPipelineState object

It is hard to believe that I can run the code in iOS simulator, but I CANT run this code ON macOS. My computer is MBP 14’ M1 Pro.

That is odd. It runs on my M1 Mac mini and M1 MBP, and if it runs in Simulator, it ought to run in macOS. I’m making sure my M1 MBP is up-to-date and I’ll check it again there too after updating everything.

  1. Is it only this chapter, or is it the same for all chapter sample codes?

  2. What are your MBP specs? - OS version, Xcode version, RAM.

And welcome to the forums :smiling_face:!

Thanks for the reply. I tried to run sample code in later chapter and I CANT run them with same error(Some even have compilation errors).
My system information is as follows and my Xcode version is 14.3

Another suggestion to try is cleaning everything, if you haven’t already tried that.

  1. Go to Xcode Settings → Locations. Click on the arrow that takes you to the DerivedData directory.

Delete all the subdirectories in the DerivedData directory. These are old builds from all your apps.

  1. Clean the project using cmd-shift-K.

  2. Quit Xcode.

  3. Restart your computer.

  4. Try building and running the project again.

Edit: Just saw your post. Probably won’t work, but always worth trying :D. Especially rebooting.

What kind of compilation errors do you get?

You said this started with Chapter 4? Were you able to run Chapters 1 - 3?

I tried clean build and reboot first and it didn’t work :sob:
When I tried the sample of Chapter 6 before, there is a compile error and it disappeared after I cleaned the old build :confused:
And I am able to run Chapter 1-3 in playground

It becomes much more weird! I can run this sample on may i9 iMac but it dead on my M2 MBA with same error! :sob:

Problem solved! The reason is I put this project in iCloud and it has some bug. When I move this project out it works. :sob:

1 Like

Oh I’m so happy! :sweat_smile: Thank you so much for reporting back.

I will have to remember to ask this - I think someone else had this problem too. I don’t know why it wouldn’t work. Perhaps local bits are disappearing occasionally.

1 Like

Just guessing it may have to do with the build folders?

1 Like

Can I add my tuppence worth?
Caroline you will remember our correspondence a few weeks ago concerning massive problems with my old 2015 machine.
Well I’ve just received my new M2 Max machine, loaded Xcode and your tutorials and ran the first 10 chapters or so with recurrent problems. To take this chapter 4 as a simple example, it runs on Mac and in simulator, but the previews work only for iOS. When I try to preview for macOS, I get this:

The first few lines of the diagnostic report are:

Incident Identifier: 4490D944-F436-4171-8521-44C6818D753F
CrashReporter Key: 7FE60CE1-FEC0-4D05-A0AC-4B3B52B0204D
Hardware Model: Mac14,6
Process: promotedcontentd [10336]
Path: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/libexec/promotedcontentd
Identifier: promotedcontentd
Version: ???
Code Type: ARM-64 (Native)
Role: Unspecified
Parent Process: launchd_sim [10118]
Coalition: com.apple.CoreSimulator.SimDevice.188B917D-471F-4A7B-AD67-64F1424A8899 [13093]
Responsible Process: SimulatorTrampoline [3863]

Date/Time: 2023-05-23 17:24:36.2350 +0100
Launch Time: 2023-05-23 17:24:36.1700 +0100
OS Version: macOS 13.2.1 (22D68)
Release Type: User
Report Version: 104

Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001a71fcfcc
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [10336]

Triggered by Thread: 0

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

regards

Are your projects in iCloud?

No.
So here’s what I’ve done. I built new projects, load your code file by file and voila, everything works.

My feeling is that every time Xcode gets any update from Apple, they mess about with some of the deep down parameters and cause all kinds of misery. There is so much going on at this specialist hidden level that I know nothing about.

My projects look different to yours. The distinction between iOS and macOS is much less evident, there’s no shared folder and only a single target though it runs both iPhone and Mac apps.

The good news is that it works. The bad news is an overhead as I proceed through the book.

All the best

1 Like

Thank you for sharing this..