Group Group Group Group Group Group Group Group Group

"Stall" on iPhone X when running final project of Chapter 22

When I try to run the final code from Chapter 22 on my iPhone X it basically just stalls. It doesn’t crash, just stops executing code. I see one “Updating hud” message and then nothing. The screen shows the accelerator pedal but is black otherwise.

I’ve traced this down to:

scene.postProcessNodes.forEach { node in
  node.postProcess(inputTexture: drawable.texture)
}

If I comment it out the app runs as expected (without the HUD).

Adding debug code and stepping through in the debugger, the app seems to make it through the postProcess method but stalls on returning to call. I have no idea why this would be.

I little more debugging and I think this issue may be related to the one I posted about in Chapter 14. It seems that HudNode is getting it’s dimensions from the macOS window, not the iOS screen. The size passed into init is size: CGSize (width = 375, height = 812). renderPass then inherits this size making the two elements of the arguments array have different sizes.

(lldb) po arguments
▿ 2 elements

  • 0 : <CIImage: 0x282cec1e0 extent [0 0 375 812]>
    MTLTexture 0x2834c0900 BGRA8Unorm extent=[0 0 375 812]
  • 1 : <CIImage: 0x282cec1d0 extent [0 0 1125 2436]>
    MTLTexture 0x283b6a640 BGRA8Unorm extent=[0 0 1125 2436]

resulting in:

(lldb) po outputImage
<CIImage: 0x282ce8740 extent [0 0 375 812]>
colorkernel hudBlend(hudTexture,drawableTexture) extent=[0 0 375 812]
MTLTexture 0x2834c0900 BGRA8Unorm extent=[0 0 375 812]
MTLTexture 0x283b6a640 BGRA8Unorm extent=[0 0 1125 2436]

It’s all strange because if you look at metalView in viewDidLoad you see:

which looks correct. However,

(lldb) po metalView
<CarGame_iOS.GameView: 0x111d09830; frame = (0 0; 375 812); autoresize = W+H; layer = <CAMetalLayer: 0x280597c40>>

which seems incorrect.

Unfortunately, if you’re on Xcode 11 or Catalina, then, as noted on page 653 of the pdf, CIContext.render hangs the app. It should work in Xcode 10, Mojave.

That reminds me to check whether I reported this to Apple.

Btw, it’s a good idea when reporting a problem, to add your hardware (which we know is an NVIDIA GPU :cry: on macOS and an iPhone X) and your operating systems and Xcode version.

1 Like

Sorry I missed that note and neglecting to post my hardware/software details. The notes are not as noticeable in Books.app as they are in the pdf (at least in dark mode).

Odd that the macOS version affects the iOS behavior, but I suppose maybe Xcode or the compiler are the difference. Sigh, two steps forward, and one step back.

1 Like