firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
224 stars 37 forks source link

[Bug] App freze and crash, if LogEvent called before Firebase init #513

Closed khrm355 closed 1 year ago

khrm355 commented 1 year ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

On app startup, I send App version and OS version with FirebaseAnalytics.LogEvent(), but it instantly freeze my app in editor or build.

I initilize Firebase with this code;

FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);

        var dependencyStatus = task.Result;
        if (dependencyStatus == Firebase.DependencyStatus.Available)
        {
            // Create and hold a reference to your FirebaseApp,
            // where app is a Firebase.FirebaseApp property of your application class.
            // Crashlytics will use the DefaultInstance, as well;
            // this ensures that Crashlytics is initialized.
            Firebase.FirebaseApp app = Firebase.FirebaseApp.DefaultInstance;

            // Set a flag here for indicating that your project is ready to use Firebase.
            IsInitialized = true;
        }
        else
        {
            UnityEngine.Debug.LogError(System.String.Format(
                "Could not resolve all Firebase dependencies: {0}",dependencyStatus));
            // Firebase Unity SDK is not safe to use here.
        }
    });

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?

stanislavsmagin commented 1 year ago

I have the same problem with 10.0.1 and Unity 2021.3.11f1

a-maurice commented 1 year ago

I haven't had any luck reproducing this on my end. Can I ask why you need to LogEvent before the initialization, and can't wait until afterwards? It is definitely recommended you initialize before doing any of the other calls, but it shouldn't freeze things.

Something you can try is adding:

Firebase.App.LogLevel = Firebase.LogLevel.Debug;

before any of the other calls, which will make it log more what is happening, which might give some insight as to the problem.

khrm355 commented 1 year ago

@a-maurice I fixed my issue with creating a callback under ContinueWith(task =>. Well let me explain my usage, I call initialize firebase at the beginning. After the initialize function, I also call log.event to send if the app or os is updated. I wonder if it's normal behavior to freeze and crash the whole game if Firebase isn't initialized somehow. Isn't that should be queue that log? event until firebase initializes?

I had to downgrade my firebase SDKs to 9.6.0 as the 10.0.1 package is not compatible with Ironsource adapters, I will reproduce this in a new project and share it here.

a-maurice commented 1 year ago

It definitely shouldn't be freezing or anything, which is the odd part. Especially in editor, where Analytics doesn't reach out to the backend at all. If you do have anything you can share that reproduces this, or any logs from the freeze, that'd be great. Especially if it is in the editor, the Unity editor logs might have some hints as to what the problem is.

google-oss-bot commented 1 year ago

Hey @khrm355. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 1 year ago

Since there haven't been any recent updates here, I am going to close this issue.

@khrm355 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.