Image textures cause runtime crashes - what's the workaround?

I've had no issue calling image files in my .swift files, but they are causing crashes when used in my .SKS files. When I set a sprite texture to an image in the inspector/ editor bar, at runtime when that sprite is being called I get the error: "Cannot get value with size 16. The type encoded as {CGRect={CGPoint=dd}{CGSize=dd}} is expected to be 32 bytes." From my research it has something to do with Apple switching from 32 to 64 bite machines. From chatGPT “SpriteKit under the hood uses NSKeyedUnarchiver to load your .sks file. That unarchiver decodes each archived property by reading a fixed‑size blob of bytes and mapping it into a C struct. In your case it ran into a mismatch”. I am using a 64-bite machine to write my code and 64-bite simulators and physical devices, so there isn't a clear cause of the mismatch. My scenes play fine in Xcode 16's preview window and my code builds, it just crashes at runtime.

When I don’t use image textured assets in the SKS file it works fine. It loads animated labels, and plain color squares. I’ve been able to work around this for static things like a sprite with a background texture by. in a normal non-game swift file, writing code like:

if let scene = SKScene(fileNamed: "GameScene2") {
    let bg = SKSpriteNode(imageNamed: "YourBackgroundImage")
    bg.position = CGPoint(x: scene.frame.midX, y: scene.frame.midY)
    bg.zPosition = -1
    scene.addChild(bg)
}

The issue now is I want to make a particle emitter and other non static sprites, but my understanding of their properities isn’t deep enough to create them without the editor. Also when I set SKTexture in a swift file that causes the same runtime crash with the 16/32 error. Could you help me figure out how to fix the bug so I can use the editor again? Otherwise could you help me figure out how to write a workaround like I do for background images? I have a feeling the answer is in writing my own NSKeyedUnarchiver but I don’t know how to make sure it’s called instead of the default one. I've already tried cleaning my code multiple times and deleting and reading sprite nodes. Thank you.

Answered by DTS Engineer in 849550022

Can you provide a small Xcode project that can be used to reproduce these problems? I'm glad to take a look.

Can you provide a small Xcode project that can be used to reproduce these problems? I'm glad to take a look.

I find this problem too. i creat one .SKS.file, and then add tile map node to it, but it crash.
"sandTest01 crashed due to an uncaught exceptionNSInvalidArgumentException. Reason: Cannot get value with size 16. The type encoded as {CGRect={CGPoint=dd}{CGSize=dd}} is expected to be 32 bytes.".
what is intresting is that when i use the Sample Hexagonal Tile Set , it won't crash, it just crash when i use my own Tile Set.
github xcode project

thank for your help!

Thanks for sending a sample. I'm going to try use it to reproduce your results here.

@DTS Engineer did you get a chance to investigate this? Encountering similar issues when trying to use the SKS GUI editor…

Hello zoeycat

I am not the Apple engineer who responded above, however I was able to replicate this crash using your project. Thank you.

Would you please submit a feedback issue to the SpriteKit framework area with your project attached. I do believe there is an Xcode bug that needs investigation. Please post your feedback number here for the record.

As a workaround can you try:

  1. Quit Xcode
  2. Open Xcode and your project. Avoid opening other projects until completing step (4).
  3. Open MyTileSet.sks, make any change, and save the changes. Avoid opening other files in your project before MyTileSet.sks if possible.
  4. Build & run your app. See if it still crashes.

-- Justin

Thank you! This workaround worked perfectly! I checked on both my own project running on Mac, as well as the sample project posted by zoeycat. Xcode 26.1.1.

Thank you again for this workaround, as I was considering having to write all of my scenes in code - and that did not spark joy.

Image textures cause runtime crashes - what's the workaround?
 
 
Q