Unity Daydream CalledFromWrongThreadException

We receive error reports from Crashlytics, affecting a significant part of our users (about 10% of them). This is a call to CalledFromWrongThreadException.

The problem is that I do not know what causes the problem, and I do not have it. Here is the log:

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) is not very useful here, since the source is unknown, I think it can be obtained from a third-party library (GVR SDK, Fabric ...).

Does anyone have the same problem?

For reference, we use the Unity version: 5.6.0f3, and the error is reported only for Pixel and Pixel XL phones.

+5
source share
1 answer

I don’t have all the details about your project, and mistakes that cannot be reproduced inside the house are the worst. Nevertheless, I will try to give some advice on what is happening. Perhaps these tips may shed some light and help you figure out the cause of the error:

CalledFromWrongThreadException

In Android, access to a view is only available from the stream that created it. This is true for other environments ( WinForms , WPF , etc.). This exception means that something is trying to access some user interface element (SurfaceView) from the wrong stream.

com.unity3d.player.UnityPlayer $ c.run

The stack trace comes from some special Unity plumbing code. Although this does not give a hint where this call comes from (in C # code), it may mean that the code appeared in C # (using calls to AndroidJavaObject or AndroidJavaClass). Unity scripting thread is not the same as the main Android thread, so this makes sense along with the type of exception you get.

As a test, I used this code to simulate the same exception:

 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); } 

This led to the following exception, which is very similar to the one you get (at least in its root).

E / ViewRootImpl (19244): com.test.crash.GameActivity: Only the original thread that created the view hierarchy can touch its views. E / ViewRootImpl (19244): java.lang.RuntimeException E / ViewRootImpl (19244): when android.view.ViewRootImpl.checkThread (ViewRootImpl.java:7105) E / ViewRootImpl (19244): when android.view.ViewRootImpl.invalidateChildInParent ViewRootImpl.java:1139) E / ViewRootImpl (19244): with android.view.ViewGroup.invalidateChild (ViewGroup.javahaps2525) E / ViewRootImpl (19244): with android.view.View.invalidateInternal (View.java:13669) E / ViewRootImpl (19244): when android.view.View.invalidate (View.java:13633) E / ViewRootImpl (19244): on android.view.View.onFocusChanged (View.java:6204) E / ViewRootImpl (19244) : when android.view.View.clearFocusInternal (View.java:6089) E / ViewRootImpl (19244): on android.view.View.unFocus (View.java:6122) E / ViewRootImpl (19244): when android.view. ViewGroup.unFocus (ViewGroup.java:997) E / ViewRootImpl (19244): with android.view.ViewGroup.removeAllViewsInLayout (ViewGroup.java:4946) E / ViewRootImpl (19244): with android.view.ViewGroup.removeAllViews (ViewGroup. java : 4905) E / ViewRootImpl (19244): when com.android.internal.policy.PhoneWindow.setContentView (PhoneWindow.java:410) E / ViewRootImpl (19244): when android.app.Activity.setContentView (Activity.java:2423 ) E / ViewRootImpl (19244): at com.unity3d.player.UnityPlayer.nativeRender (own 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)

Summary

As I mentioned earlier, this only gives you a direction where to look. We hope you can find potential locations that may be causing this (possibly the plugin code). I would be happy to help (in the comments or feel free to contact me ).

0
source

Source: https://habr.com/ru/post/1268354/


All Articles