2017-05-30 38 views
5

我們從Crashlytics獲得錯誤報告,影響了我們用戶的相當大一部分(其中約10%)。這是一個CalledFromWrongThreadException。Unity Daydream CalledFromWrongThreadException

問題是我不知道是什麼導致了這個問題,我自己也沒有。下面是日誌:

Caused by android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. 
     at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7282) 
     at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1197) 
     at android.view.ViewGroup.invalidateChild(ViewGroup.java:5748) 
     at android.view.View.invalidateInternal(View.java:15082) 
     at android.view.View.invalidate(View.java:15046) 
     at android.view.View.invalidate(View.java:15029) 
     at android.view.SurfaceView$1.handleMessage(SurfaceView.java:142) 
     at android.os.Handler.dispatchMessage(Handler.java:105) 
     at android.os.Looper.loop(Looper.java:164) 
     at com.unity3d.player.UnityPlayer$c.run(Unknown Source:20) 

com.unity3d.player.UnityPlayer$c.run(Unknown Source:20)是不是真的有幫助這裏的起源是未知的,我猜它可能來自第三方庫(GVR SDK,布...)。

有沒有人有同樣的問題?

僅供參考,我們使用Unity版本:5.6.0f3,並且僅報告Pixel和Pixel XL手機的錯誤。

回答

0

我沒有關於您的項目的所有細節,而且無法在內部複製的錯誤是最糟糕的一種。不過,我會試着提供一些關於發生了什麼的提示。也許這些提示可以提供一些線索,幫助你找出錯誤的根源:

CalledFromWrongThreadException

在Android上,一個視圖只能從創建它的線程訪問。這對其他環境也是如此(WinFormsWPF等)。這個異常意味着某些東西試圖從錯誤的線程訪問某個UI元素(SurfaceView)。

com.unity3d.player.UnityPlayer $ c.run

堆棧跟蹤從一些自定義的統一管道代碼起源。雖然這並不能說明這個調用來自哪裏(在C#代碼中),但這可能意味着代碼來自C#(使用AndroidJavaObject或AndroidJavaClass調用)。 Unity的腳本線程與Android的主線程並不相同,因此這與您獲得的異常類型一起合理。

作爲一個測試,我用這個代碼模擬了相同的異常:

using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) 
{ 
    var activity = actClass.GetStatic<AndroidJavaObject>("currentActivity"); 

    // cause an exception to be thrown 
    activity.Call("setContentView", 15); 
} 

這導致以下異常,這是非常相似,你得到(至少在一個其根)。

E/ViewRootImpl(19244): com.test.crash.GameActivity : Only the original thread that created a view hierarchy can touch its views. E/ViewRootImpl(19244): java.lang.RuntimeException E/ViewRootImpl(19244): at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:7105) E/ViewRootImpl(19244): at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1139) E/ViewRootImpl(19244): at android.view.ViewGroup.invalidateChild(ViewGroup.java:5254) E/ViewRootImpl(19244): at android.view.View.invalidateInternal(View.java:13669) E/ViewRootImpl(19244): at android.view.View.invalidate(View.java:13633) E/ViewRootImpl(19244): at android.view.View.onFocusChanged(View.java:6204) E/ViewRootImpl(19244): at android.view.View.clearFocusInternal(View.java:6089) E/ViewRootImpl(19244): at android.view.View.unFocus(View.java:6122) E/ViewRootImpl(19244): at android.view.ViewGroup.unFocus(ViewGroup.java:997) E/ViewRootImpl(19244): at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:4946) E/ViewRootImpl(19244): at android.view.ViewGroup.removeAllViews(ViewGroup.java:4905) E/ViewRootImpl(19244): at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:410) E/ViewRootImpl(19244): at android.app.Activity.setContentView(Activity.java:2423) E/ViewRootImpl(19244): at com.unity3d.player.UnityPlayer.nativeRender(Native Method) E/ViewRootImpl(19244): at com.unity3d.player.UnityPlayer.a(Unknown Source) E/ViewRootImpl(19244): at com.unity3d.player.UnityPlayer$c$1.handleMessage(Unknown Source) E/ViewRootImpl(19244): at android.os.Handler.dispatchMessage(Handler.java:98) E/ViewRootImpl(19244): at android.os.Looper.loop(Looper.java:173) E/ViewRootImpl(19244): at com.unity3d.player.UnityPlayer$c.run(Unknown Source)

摘要

正如我前面提到的,這只是給你一個方向在哪裏看。希望你能夠找到可能成爲這個原因的可能位置(可能是插件代碼)。我很樂意進一步協助(在評論中,或者隨時感謝contact me)。

相關問題