firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
819 stars 424 forks source link

unity editor crash when read data on firestore #1325

Closed amir1387aht closed 1 year ago

amir1387aht commented 1 year ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

hello, i want use firestore for my app chat i impelented firebase sdk, Resolved android dep, and... now when i want to read\write data from firestore, unity editor gets crash(15 crash today!) other package work find(but auth get me error that i fix later)

Steps to reproduce:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? What's the issue repro rate? (eg 100%, 1/5 etc) samples code on firebase docs have get me crash too, 100%

What happened? How can we make the problem occur? consol not show anything, it just crash and clode unity

If you have a downloadable sample project that reproduces the bug you're reporting, you will likely receive a faster response on your issue.

Relevant Code:

    public virtual void Start()
    {
        app = FirebaseApp.Create(new AppOptions
        {
            DatabaseUrl = new Uri("i hide it"),
            ProjectId = "i hide it",
            ApiKey = "i hide it",
            AppId = "i hide it"
        });

        FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
        {
            dependencyStatus = task.Result;
            if (dependencyStatus == DependencyStatus.Available)
            {
                InitializeFirebase();
            }
            else
            {
                Debug.LogError(
                  "Could not resolve all Firebase dependencies: " + dependencyStatus);
            }
        });
    }

    protected void InitializeFirebase()
    {
        auth = FirebaseAuth.GetAuth(app);
        db = FirebaseFirestore.GetInstance(app);

        StartCoroutine("get-chats");
    }

   public IEnumerator get-chats()
    {
        var doc = db.Document("1.2");
        var getTask = doc.GetSnapshotAsync(Source.Cache);
        yield return AwaitCompletion(getTask);
        getTask.ContinueWithOnMainThread(task =>
        {
            Dictionary<string, object> d = task.Result.ToDictionary();
            print(d["user-chat"]);
        });
    }

    public static IEnumerator AwaitCompletion(Task t)
    {
        yield return new WaitUntil((() => t.IsCompleted));
    }
google-oss-bot commented 1 year ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

milaGGL commented 1 year ago

Hi @amir1387aht, I have a suspicion that this is related to the known issue with the unity SDK when creating multiple instances of the app. This might be a related issue. https://github.com/firebase/quickstart-unity/issues/1284

Could you please try the code below, and see if it resolves the issue?

#if UNITY_EDITOR
db = FirebaseFirestore.DefaultInstance;
db.Settings.PersistenceEnabled = false;
#endif
amir1387aht commented 1 year ago

hi @milaGGL , thanks for your help, Your Code worked fine, but because I wanna publish app in iran, firestore doesn't support iran, clinet say 'user is offline' but internet connection was OK

I need to find another database for my chat system,

milaGGL commented 1 year ago

My pleasure to help. I am closing this ticket, but please feel free to re-open it or create a new one if you have further questions.