firebase / quickstart-unity

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

[Bug] 'GetSnapshotAsync()' never returns #1279

Closed tdelahayeEnsicaen closed 2 years ago

tdelahayeEnsicaen commented 2 years ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

When called, the "GetSnapshotAsync()" function does not terminate and no error is displayed

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)

What happened? How can we make the problem occur? This could be a description, log/console output, etc.

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

Build and run the app on an android phone

Click on "Begin Resolving"

The app will freeze because "GetSnapshotAsync()" never return

Relevant Code:

          CollectionReference anchorsRef = db.Collection("anchors");

          return anchorsRef.GetSnapshotAsync().ContinueWithOnMainThread(task =>
          {
              QuerySnapshot snapshot = task.Result;
              var history = new CloudAnchorHistoryCollection();

              foreach (var document in snapshot)
              {
                  history.Collection.Add(new CloudAnchorHistory(document.Id, document.GetValue<string>("id"), Convert.ToDateTime(document.GetValue<string>("time"))));
              }

              return history;
          }).Result;

https://ensicaenfr-my.sharepoint.com/:u:/g/personal/tom_delahaye_ecole_ensicaen_fr/EU0tk3d6xRVAsp-D7sY0igIBNofJw1l0K616ey8ZVzbEgg?e=DVwYkL

google-oss-bot commented 2 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

paulinon commented 2 years ago

Hi @tdelahayeEnsicaen,

I was able to observe this behavior in the sample project you provided, and I also noticed that it makes use of the AR Foundation and AR Core SDKs. Could you confirm if the behavior persists with only the Firebase SDK in the project? It would be great if you could provide a more minimal, reproducible example of your implementation as this can be used as a baseline for troubleshooting.

tdelahayeEnsicaen commented 2 years ago

Hello, thank you for your reply

I have created a minimal example to reproduce the bug. I also removed AR Core and AR Foundation.

https://ensicaenfr-my.sharepoint.com/:u:/g/personal/tom_delahaye_ecole_ensicaen_fr/EQT0zRnNtopGpkewXciZlmYBFJOO7IotLxUjOveVbAqFdg?e=tzxbt2

paulinon commented 2 years ago

HI @tdelahayeEnsicaen,

I was able to encounter the issue with the minimal example you provided. The result of the read task isn't typically stored in a variable. I've modified the function so that the app will no longer freeze:

CollectionReference anchorsRef = db.Collection("anchors");

        anchorsRef.GetSnapshotAsync().ContinueWithOnMainThread(task =>
        {
            QuerySnapshot snapshot = task.Result;
            var history = new List<List<string>>();

            foreach (var document in snapshot)
            {
                var entry = new List<string>();

                entry.Add(document.Id);
                entry.Add(document.GetValue<string>("id"));
                entry.Add(document.GetValue<string>("time"));

                history.Add(entry);
            }
        });

Let me know if this works for your use case.

tdelahayeEnsicaen commented 2 years ago

Yes, that solves my problem, thank you very much!