gorastudio-git / SCNRecorder

The best way to record your AR experience!
MIT License
201 stars 51 forks source link

ARView+SelfSceneRecordable Crash #56

Closed frank-1992 closed 2 years ago

frank-1992 commented 2 years ago

When I set the minimum deployments 'iOS 10.0' and run the example ,

_cancelable = scene.subscribe( to: SceneEvents.Update.self ) { [weak sceneRecorder] (_) in sceneRecorder?.render() } SceneEvents.Update will crash, can you help to me?

v-grigoriev commented 2 years ago

RealityKit is iOS 13+, there are known issues with lower version usage, maybe https://stackoverflow.com/questions/71000365/realitykit-app-and-lower-ios-deployment-target will help you.

v-grigoriev commented 2 years ago

iOS 16 is available already I will be dropping iOS 12 support anytime soon.

frank-1992 commented 2 years ago

RealityKit is iOS 13+, there are known issues with lower version usage, maybe https://stackoverflow.com/questions/71000365/realitykit-app-and-lower-ios-deployment-target will help you.

thank you

frank-1992 commented 2 years ago

RealityKit is iOS 13+, there are known issues with lower version usage, maybe https://stackoverflow.com/questions/71000365/realitykit-app-and-lower-ios-deployment-target will help you.

I have participated in the discussion below this link. Now that xcode14 has been fixed, can the code here be used without combine?

v-grigoriev commented 2 years ago

I have participated in the discussion below this link. Now that xcode14 has been fixed, can the code here be used without combine?

SceneRecorder needs to be notified when a new frame rendered. If you can find another approach to get such information form RealityKit you are welcome to contribute :)

you can trigger sceneRecorder?.render() manually, for example by timer or CADisplayLink, but it will be inaccurate.

frank-1992 commented 2 years ago

I have participated in the discussion below this link. Now that xcode14 has been fixed, can the code here be used without combine?

SceneRecorder needs to be notified when a new frame rendered. If you can find another approach to get such information form RealityKit you are welcome to contribute :)

you can trigger sceneRecorder?.render() manually, for example by timer or CADisplayLink, but it will be inaccurate.

Thanks for your answer, I will try it

frank-1992 commented 2 years ago

I have participated in the discussion below this link. Now that xcode14 has been fixed, can the code here be used without combine?

SceneRecorder needs to be notified when a new frame rendered. If you can find another approach to get such information form RealityKit you are welcome to contribute :)

you can trigger sceneRecorder?.render() manually, for example by timer or CADisplayLink, but it will be inaccurate.

I have finished it. Can you help to check it, is it ok? @available(iOS 13.0, *) extension SceneRecorder: ARSessionDelegate { public func session(_ session: ARSession, didUpdate frame: ARFrame) { render() } }

frank-1992 commented 2 years ago

`import Foundation import RealityKit import SCNRecorder import Combine import ARKit

private var cancellableKey: UInt8 = 0

@available(iOS 13.0, *) extension ARView: SelfSceneRecordable {

var _cancelable: Cancellable? { get { objc_getAssociatedObject( self, &cancellableKey ) as? Cancellable } set { objc_setAssociatedObject( self, &cancellableKey, newValue, .OBJC_ASSOCIATION_RETAIN ) } }

public func injectRecorder() { do { sceneRecorder = try SceneRecorder(self)

if !targetEnvironment(simulator)

  session.delegate = sceneRecorder
  #endif
}
catch { assertionFailure("\(error)") }

} }

@available(iOS 13.0, *) extension SceneRecorder: ARSessionDelegate { public func session(_ session: ARSession, didUpdate frame: ARFrame) { render() } } ` I have tested it

frank-1992 commented 2 years ago

inaccurate

emmm, but my project must be set to iOS10.0(minimum deployments)

v-grigoriev commented 2 years ago

please don't confirm third party classes to third party protocols. it might lead to unexpected results. I don't remember if I used session delegate somewhere inside the library, if not it should be fine.

It might be a bit inaccurate because the session(_ session: ARSession, didUpdate frame: ARFrame) function is called a moment before the content is rendered. But it might be ok.

v-grigoriev commented 2 years ago

Another thing here is that the content might be changed from somewhere else, without changing ARFrame, so this callback won't fire. but It should still work for reality kit.

v-grigoriev commented 2 years ago

public func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) ok thanks for your suggestion, do you think this protocol will be better?

it will, but RealityKit doesn't use SceneKit, so it just won't work. You can just create you own delegate conforming to ARSessionDelegate and call render from there.