Assertion failed after calling session.startDetecting() - Xcode 15.0 beta1 (15A5160n)

I followed the instruction in this session and tried to write a demo with Object Capture API. But there's a MTLDebugRenderCommandEncoder assertion fails every time I call session.startDetecting(), just after the bounding box shows up.

The error shows:

-[MTLDebugRenderCommandEncoder validateCommonDrawErrors:]:5780: failed assertion `Draw Errors Validation
Fragment Function(fsRealityPbr): the offset into the buffer clippingConstants that is bound at buffer index 8 must be a multiple of 256 but was set to 128.

and my code is pretty simple:

var body: some View {
    ZStack {
        ObjectCaptureView(session: session)
        if case .initializing = session.state {
            Button {
                session.start(imagesDirectory: getDocumentsDir().appendingPathComponent("Images/"), configuration: configuration) // 💥
            } label: {
                Text("Prepare")
            }
        } else if case .ready = session.state {
            Button {
                session.startDetecting()
            } label: {
                Text("Continue")
            }
        } else if case .detecting = session.state {
            Button {
                session.startCapturing()
            } label: {
                Text("Start Capture")
            }
        }
    }
}

I'm wondering if anyone else is facing the same problem or if there's an error on my side?

Answered by CiyouLee in 755433022

UPDATE - Workaround

You can actually disable Metal API Validation in your build scheme to temporally bypass the internal assertion for debugging other codes, and wait until Apple release their fixes.

There's still some other internal crashes and assertion cannot be bypassed with this workaround, but these don't happens every time. Finally I was able to get an USDZ model.

There was a typo in the code of my original post, to be clear, the assertion failure happens after calling startDetecting instead of session.start(imagesDirectory:configuration:)

if case .initializing = session.state {
            Button {
                session.start(imagesDirectory: getDocumentsDir().appendingPathComponent("Images/"), configuration: configuration) // everything's alright after this
            } label: {
                Text("Prepare")
            }
        } else if case .ready = session.state {
            Button {
                session.() // 💥
            } label: {
                Text("Continue")
            }
        }

I have the same error every time the bounding box reaches the end of it's animation. This only happens when tethered to XCode however.

When I run on the device, force the application to stop, detach from XCode and relaunch the app it will run without crashing.

However not being able to debug and see what other error messages might show up makes this an exceptionally difficult API to work with.

Same here, filed a FB: FB12281202

Accepted Answer

UPDATE - Workaround

You can actually disable Metal API Validation in your build scheme to temporally bypass the internal assertion for debugging other codes, and wait until Apple release their fixes.

There's still some other internal crashes and assertion cannot be bypassed with this workaround, but these don't happens every time. Finally I was able to get an USDZ model.

Now can anyone please explain how to disable the Metal API Validation?

I tried switching this to "Disabled" or "OpenGL ES"

Cleaned the Build folder, built again.

But I am still getting the same error.

[Deleted]

Assertion failed after calling session.startDetecting() - Xcode 15.0 beta1 (15A5160n)
 
 
Q