在ARKit面部追踪和后置摄像头之间进行Unity切换?

时间:2018-08-13 11:52:12

标签: ios unity3d arkit

我正在使用ARKit在Unity for iOS中创建应用程序。我想先创建一个校准场景,该场景使用ARKit人脸跟踪工具来测量手机到人脸的距离。这些信息被馈送到下一个场景,然后使用后置摄像头进行AR游戏。

我已经成功地分别创建了两个场景,并添加了一个GUI按钮,该按钮应在电话应用程序中切换它们。但是,当我构建应用程序对其进行测试时,按下按钮会导致应用程序崩溃。

有人知道iOS上是否支持这种类型的相机切换吗?如果是这样,关于如何使其工作的任何建议?我是否需要更改场景中的任何配置?

非常感谢!

编辑:我认为问题在于,更改场景时,不会破坏ARSession对象(它具有用于面部跟踪和后置摄像头AR的不同配置)。我不确定如何破坏Unity以破坏此会话并开始一个新会话。

堆栈跟踪(最后一部分)

enter code here
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIWindow rootViewController]
PID: 433, TID: 61976, Thread name: UnityGfxDeviceWorker, Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4   FaceRCalibration                    0x00000001080ed07c _ZN7Vuforia4initEv + 356020
5   FaceRCalibration                    0x00000001080ed49c _ZN7Vuforia4initEv + 357076
6   FaceRCalibration                    0x0000000108239de0 _ZN7Vuforia4initEv + 1719320
7   FaceRCalibration                    0x0000000108222c34 _ZN7Vuforia4initEv + 1624684
8   FaceRCalibration                    0x000000010804f9d0 onSurfaceCreated + 32
9   FaceRCalibration                    0x000000010784221c _ZN9GfxDevice26InsertCustomMarkerCallbackEPFviEi + 48
10  FaceRCalibration                    0x0000000107c4252c _ZN15GfxDeviceWorker10RunCommandER20ThreadedStreamBuffer + 11056
11  FaceRCalibration                    0x00000001073591c8 GfxDeviceWorkerAutoreleasePoolProxy + 68
12  FaceRCalibration                    0x0000000107c47fe0 _ZN15GfxDeviceWorker6RunExtER20ThreadedStreamBuffer + 84
13  FaceRCalibration                    0x0000000107c47f80 _ZN15GfxDeviceWorker3RunEv + 140
14  FaceRCalibration                    0x0000000107c3f86c _ZN15GfxDeviceWorker18RunGfxDeviceWorkerEPv + 12
15  FaceRCalibration                    0x0000000107707e5c _ZN6Thread16RunThreadWrapperEPv + 64
16  libsystem_pthread.dylib             0x0000000182d85220 <redacted> + 272
17  libsystem_pthread.dylib             0x0000000182d85110 <redacted> + 0
18  libsystem_pthread.dylib             0x0000000182d83b10 thread_start + 4
2018-08-13 15:02:44.496950+0100 FaceRCalibration[433:61976] [reports] Main Thread Checker: UI API called on a background thread: -[UIWindow rootViewController]
PID: 433, TID: 61976, Thread name: UnityGfxDeviceWorker, Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
4   FaceRCalibration                    0x00000001080ed07c _ZN7Vuforia4initEv + 356020
5   FaceRCalibration                    0x00000001080ed49c _ZN7Vuforia4initEv + 357076
6   FaceRCalibration                    0x0000000108239de0 _ZN7Vuforia4initEv + 1719320
7   FaceRCalibration                    0x0000000108222c34 _ZN7Vuforia4initEv + 1624684
8   FaceRCalibration                    0x000000010804f9d0 onSurfaceCreated + 32
9   FaceRCalibration                    0x000000010784221c _ZN9GfxDevice26InsertCustomMarkerCallbackEPFviEi + 48
10  FaceRCalibration                    0x0000000107c4252c _ZN15GfxDeviceWorker10RunCommandER20ThreadedStreamBuffer + 11056
11  FaceRCalibration                    0x00000001073591c8 GfxDeviceWorkerAutoreleasePoolProxy + 68
12  FaceRCalibration                    0x0000000107c47fe0 _ZN15GfxDeviceWorker6RunExtER20ThreadedStreamBuffer + 84
13  FaceRCalibration                    0x0000000107c47f80 _ZN15GfxDeviceWorker3RunEv + 140
14  FaceRCalibration                    0x0000000107c3f86c _ZN15GfxDeviceWorker18RunGfxDeviceWorkerEPv + 12
15  FaceRCalibration                    0x0000000107707e5c _ZN6Thread16RunThreadWrapperEPv + 64
16  libsystem_pthread.dylib             0x0000000182d85220 <redacted> + 272
17  libsystem_pthread.dylib             0x0000000182d85110 <redacted> + 0
18  libsystem_pthread.dylib             0x0000000182d83b10 thread_start + 4
2018-08-13 15:02:44.632260+0100 FaceRCalibration[433:61976] DEBUG/AR(433) UIView has CAMetalLayer layer class
2018-08-13 15:02:44.632402+0100 FaceRCalibration[433:61976] DEBUG/AR(433) UIView does not respond to selector renderFrameVuforia
2018-08-13 15:02:44.632479+0100 FaceRCalibration[433:61976] DEBUG/AR(433) Could not find a UIView with CAEAGLLayer or CAMetalLayer layer class that responds to selector renderFrameVuforia
2018-08-13 15:02:44.864480+0100 FaceRCalibration[433:61734] [Common] _BSMachError: port da03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
2018-08-13 15:02:44.887877+0100 FaceRCalibration[433:61734] [Common] _BSMachError: port da03; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
-> applicationWillResignActive()
ar_session_interrupted
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
UnityEngine.XR.iOS.UnityARSessionNativeInterface:_ar_session_interrupted()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

-> applicationDidEnterBackground()
2018-08-13 15:03:00.267669+0100 FaceRCalibration[433:62230] TIC Read Status [6:0x0]: 1:57
2018-08-13 15:03:00.267723+0100 FaceRCalibration[433:62230] TIC Read Status [6:0x0]: 1:57
2018-08-13 15:03:04.129255+0100 FaceRCalibration[433:62583] dnssd_clientstub read_all(33) DEFUNCT
-> applicationWillEnterForeground()
-> applicationDidBecomeActive()
ar_session_interruption_ended
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
UnityEngine.XR.iOS.UnityARSessionNativeInterface:_ar_session_interruption_ended()

(Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)

Unloading 6 Unused Serialized files (Serialized files now loaded: 0)
UnloadTime: 4.989750 ms
System memory in use before: 26.3 MB.
System memory in use after: 26.4 MB.

Unloading 9 unused Assets to reduce memory usage. Loaded Objects now: 2123.
Total: 3.255875 ms (FindLiveObjects: 0.764083 ms CreateObjectMapping: 0.056708 ms MarkObjects: 2.368958 ms  DeleteObjects: 0.065208 ms)

Setting up 1 worker threads for Enlighten.
  Thread -> id: 16c77f000 -> priority: 1 
libc++abi.dylib: terminating with uncaught exception of type Il2CppExceptionWrapper
(lldb) 

1 个答案:

答案 0 :(得分:0)

我设法解决了这个问题。您必须在3个函数中检查anchorPrefab的null:FaceAdded,FaceUpdated,FaceRemoved以及OnDestroy函数,只需从头开始释放事件委托并隐藏anchorPrefab。 完整的源代码如下。

INSERT