В моем приложении я позволяю пользователям сохранять состояние сцены на карте мира, а затем перезагружать его позже. Когда пользователь делает это, при первой загрузке карты все работает безупречно . Карта мира загружена, успешно откалибрована по отношению к физической среде, якоря загружены, и соответствующие объекты обнаружены. Проблема начинается во второй раз, когда пользователь пытается загрузить карту мира, не выходя из приложения . Когда карта мира загружена, происходит калибровка, и якоря добавляются в сеанс, я получаю краткий sh.
Просмотр моих комментариев, чтобы лучше понять код.
func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
guard !savingWorldMap else {
print("Ignoring processed new anchors while saving world map")
return
}
anchors.forEach { anchor in
if let name = anchor.name,
let type = FurnisherType(rawValue: name) {
guard let furnisherEntity = type.entity() else { // !!! type.entity() implementation is down below
print("Failed to load entity of type \(type.rawValue)")
return
}
furnisherEntity.transform.matrix = anchor.transform
furnisherEntity.arAnchor = anchor
self.entities.append(furnisherEntity)
if self.configuringScene { // !!! Assume that this is always 'false'
self.arView.installGestures(.all, for: furnisherEntity)
self.arView.scene.addAnchor(furnisherEntity)
} else {
let anchorEntity = AnchorEntity(plane: .horizontal)
anchorEntity.addChild(furnisherEntity)
self.arView.scene.addAnchor(anchorEntity) // !!! This line is the my last line of code that executes before the crash.
}
} else {
print("Anchor with no name was added. anchor = \(anchor)")
}
}
func entity(isConfiguring: Bool = false) -> FurnisherEntity? {
let fileName = rawValue
let entity = try! Entity.load(named: fileName)
entity.name = rawValue
return FurnisherEntity(furnisher: entity, isConfiguring: false) // !!! FurnisherEntity inherits from Entity, HasCollision, HasAnchoring and HasModel.
}
Вот трассировка стека:
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGTRAP
* frame #0: 0x00000001af409ec4 libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x00000001af329724 libsystem_pthread.dylib`pthread_kill$VARIANT$armv81 + 216
frame #2: 0x00000001af215f84 libsystem_c.dylib`raise + 28
frame #3: 0x00000001ca059998 CoreRE`re::RenderFrame::emitGraph(char const*, char const*) + 512
frame #4: 0x00000001ca1c6b48 CoreRE`std::__1::__function::__func<re::RenderGraphAREmitter::RenderGraphAREmitter()::$_4, std::__1::allocator<re::RenderGraphAREmitter::RenderGraphAREmitter()::$_4>, void (re::RenderFrame&, re::RenderGraphDataStore&, re::RenderFrameDataWrapper&)>::operator()(re::RenderFrame&, re::RenderGraphDataStore&, re::RenderFrameDataWrapper&) + 1540
frame #5: 0x00000001ca1b85e8 CoreRE`re::RenderGraphEmitterBase::handleRenderData(re::RenderFrame&, re::RenderFrameDataWrapper&) + 96
frame #6: 0x00000001ca1c130c CoreRE`re::RenderGraphAREmitter::doExecute(re::RenderManager&) + 808
frame #7: 0x00000001ca20bf78 CoreRE`RERenderGraphEmitterAssetExecute + 84
frame #8: 0x00000001d8e355bc RealityKit`RealityKit.ARView.(commonRenderCallback in _1DEA12EA8F047681559567CA09DBAA37)() -> () + 440
frame #9: 0x00000001d8e34eac RealityKit`closure #2 (RealityKit.EngineRenderEvent) -> () in RealityKit.ARView.commonInit(Swift.Optional<RealityKit.__Engine>) -> () + 180
frame #10: 0x00000001d8e3b670 RealityKit`partial apply forwarder for reabstraction thunk helper from @escaping @callee_guaranteed (@unowned RealityKit.EngineRenderEvent) -> () to @escaping @callee_guaranteed (@in_guaranteed RealityKit.EngineRenderEvent) -> () + 20
frame #11: 0x00000001d864bf1c Combine`Combine.Subscribers.Sink.receive(A) -> Combine.Subscribers.Demand + 40
frame #12: 0x00000001d864c134 Combine`protocol witness for Combine.Subscriber.receive(A.Input) -> Combine.Subscribers.Demand in conformance Combine.Subscribers.Sink<A, B> : Combine.Subscriber in Combine + 20
frame #13: 0x00000001d864c624 Combine`Combine.AnySubscriberBox.receive(A.Input) -> Combine.Subscribers.Demand + 36
frame #14: 0x00000001d8e02cec RealityKit`generic specialization <RealityKit.EngineRenderEvent> of RealityKit.REEventDispatcher.receive(A) -> Combine.Subscribers.Demand + 740
frame #15: 0x00000001d8f03790 RealityKit`generic specialization <RealityKit.REEventBus, RealityKit.EngineRenderEvent> of (extension in RealityKit):RealityKit.EventService.publish<A>(_: A1, on: Swift.Optional<RealityKit.EventSource>) -> () + 112
frame #16: 0x00000001d8e10580 RealityKit`RealityKit.(engineRenderCallback in _D9B7ACB6851F1D685E72D1398FD7146D)(coreEngine: Swift.Optional<Swift.OpaquePointer>) -> __C.REEventHandlerResult + 120
frame #17: 0x00000001c9e1e634 CoreRE`re::Event<re::Engine>::raise(re::Engine*) + 64
frame #18: 0x00000001c9e1e790 CoreRE`re::Engine::doRender() + 48
frame #19: 0x00000001c9e1e0f8 CoreRE`re::Engine::timeDidChange(re::SimulationTimer*, re::SimulationTimerEventArgs const&) + 848
frame #20: 0x00000001ca1ee78c CoreRE`re::Event<re::SimulationTimer, re::SimulationTimerEventArgs const&>::raise(re::SimulationTimer*, re::SimulationTimerEventArgs const&) + 76
frame #21: 0x00000001ca1ee6e0 CoreRE`re::VariableStepTimer::onClockDidChange(re::SimulationClock*, re::SimulationClockEventArgs const&) + 244
frame #22: 0x00000001ca1ed688 CoreRE`re::Event<re::SimulationClock, re::SimulationClockEventArgs const&>::raise(re::SimulationClock*, re::SimulationClockEventArgs const&) + 68
frame #23: 0x00000001ca1edebc CoreRE`re::DisplayLinkClock::update() + 120
frame #24: 0x0000000101f5d5f8 GPUToolsCore`-[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 168
frame #25: 0x00000001b5f3f88c QuartzCore`CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 632
frame #26: 0x00000001b6009694 QuartzCore`display_timer_callback(__CFMachPort*, void*, long, void*) + 264
frame #27: 0x00000001af5678ac CoreFoundation`__CFMachPortPerform + 172
frame #28: 0x00000001af59107c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
frame #29: 0x00000001af5907a8 CoreFoundation`__CFRunLoopDoSource1 + 444
frame #30: 0x00000001af58b67c CoreFoundation`__CFRunLoopRun + 2168
frame #31: 0x00000001af58aadc CoreFoundation`CFRunLoopRunSpecific + 464
frame #32: 0x00000001b9510328 GraphicsServices`GSEventRunModal + 104
frame #33: 0x00000001b3685ae0 UIKitCore`UIApplicationMain + 1936
frame #34: 0x0000000100fc009c Sparx`main at AppDelegate.swift:15:7
frame #35: 0x00000001af414360 libdyld.dylib`start + 4