被困的Unity和Firebase事务线程

时间:2019-02-08 10:49:55

标签: c# android firebase unity3d

我目前正在使用Firebase和Unity进行开发。我遇到了线程冻结的问题。仅在Android设备上运行时,在unity编辑器中运行时不会发生此问题。

我有一个带有按钮的场景。在“按钮”上按下,将发生Firebase事务,并且场景已更改。我已经使用Android Monitor进行调查,并且收到带有以下内容的转储,例如:“ IdleHandler从firebase抛出异常”,“其他线程被捕获; signum = 11”,“主线程被捕获”

下面是在GUI中按下按钮时运行的代码示例。

似乎与github上的这个问题有关:https://github.com/firebase/quickstart-unity/issues/181

public void on buttonPress()
{

        Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug;
        Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
        {
            var dependencyStatus = task.Result;
            if (dependencyStatus == Firebase.DependencyStatus.Available)
            {
                //transaction code
                return TransactionResult.Success(data);
            }
            else
            {
                UnityEngine.Debug.LogError(System.String.Format(
                  "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
                // Firebase Unity SDK is not safe to use here.
            }
        });


        // firebase code is running, now change scene 
        SceneManager.LoadScene("blah");
    }

1 个答案:

答案 0 :(得分:0)

移动SceneManager.LoadScene(“ blah”);上

public void on buttonPress()
{

        Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug;
        Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>
        {
            console.log('before if'); //log something here
            var dependencyStatus = task.Result;
            if (dependencyStatus == Firebase.DependencyStatus.Available)
            {
                //transaction code
                console.log('true')
                return TransactionResult.Success(data);
            }
            else
            {
                UnityEngine.Debug.LogError(System.String.Format(
                  "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
                // Firebase Unity SDK is not safe to use here.
            }
            // firebase code is running, now change scene 
            SceneManager.LoadScene("blah");
        });
}

这意味着直到异步完成并且任务被调用之前,下一个场景才会加载