Quickstart-unity: Mac OS: Firebase crashing Unity2017.4.1f1 with .NET 4.6

Created on 27 Apr 2018  Â·  33Comments  Â·  Source: firebase/quickstart-unity

Hi,

I just moved my project to .NET 4.6 and noticed that Firebase is crashing the Editor under MacOS.
Is there ay way to fix this?

Thanks,

bug

All 33 comments

Could you share the editor log with the crash?
What version of the SDK are you using?

Editor-prev.log
Editor.log

Here are the files, hope it helps

I'm having the same problem, my logs look nearly identical. Unity editor is crashing about every 3 to 5th play. Anyone else?

After upgrading from Firebase 4.5.0 to 4.5.2, the problem seems to be solved.

Jinxed it. :(

It's happening a lot less now, but just got an editor crash. Similar to before, the last log items are a large number of "Firebase App Initializing..." items.
editor.log

thread_suspend failed
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Stacktrace:

Native stacktrace:

0   libmonobdwgc-2.0.dylib              0x000000013ed6db01 mono_handle_native_crash + 277
1   libsystem_platform.dylib            0x00007fff73120f5a _sigtramp + 26
2   libmonobdwgc-2.0.dylib              0x000000013ee974ec mono_class_vtable_full + 65
3   libsystem_c.dylib                   0x00007fff72ebe1ae abort + 127
4   libmonobdwgc-2.0.dylib              0x000000013eee6f20 GC_noop6 + 0
5   libmonobdwgc-2.0.dylib              0x000000013eee663a GC_stopped_mark + 62
6   libmonobdwgc-2.0.dylib              0x000000013eee6396 GC_try_to_collect_inner + 311
7   libmonobdwgc-2.0.dylib              0x000000013eee7acb GC_try_to_collect_general + 158
8   libmonobdwgc-2.0.dylib              0x000000013eee7b40 GC_gcollect + 13
9   Unity                               0x0000000100cde9bb _Z16CleanupAfterLoadv + 155
10  Unity                               0x0000000100d32858 _ZN18LoadSceneOperation19IntegrateMainThreadEv + 472
11  Unity                               0x0000000100d34a66 _ZN14PreloadManager26UpdatePreloadingSingleStepENS_21UpdatePreloadingFlagsEi + 470
12  Unity                               0x0000000100d35432 _ZN14PreloadManager35WaitForAllAsyncOperationsToCompleteEv + 114
13  Unity                               0x00000001012ebdd7 _ZN18EditorSceneManager19RestoreSceneBackupsERSt6vectorINS_11SceneBackupE13stl_allocatorIS1_L18MemLabelIdentifier105ELi16EEENS_14PlayModeChangeEb + 1815
14  Unity                               0x00000001019a8455 _ZN20PlayerLoopController13EnterPlayModeEb + 533
15  Unity                               0x00000001019a32a6 _ZN20PlayerLoopController12SetIsPlayingEb + 278
16  Unity                               0x00000001019a2af5 _ZN11Application9TickTimerEv + 4069

Anyone else experiencing Unity editor crashes with Firebase 4.5.2 and C# 4.6 scripting?

@marcz88 could you try upgrading to Firebase Unity SDK 5.0.0 ? We've resolved some cleanup issues in some components.

Thx, I upgraded yesterday and have only seen one editor crash so far. Happened when I was building, not when I was playing. So far no Play crashes which is amazing.
Reviewing the editor.log (sorry got overwritten before I could save it) it looked like the crash occurred during garbage collection, at the end of scene load, but I didn't see the same Firebase logging occurring at that time. Definitely an improvement. I'll grab the editor.log next time I have a crash.

@criistii and @marcz88 which Firebase components are you using? Also, it looks like you're both running the editor on OSX is that correct? It would be great to understand the problematic environment so we can get to the root cause of this.

I'm only using Messaging. Running:
OSX 10.13.4
Unity 2017.4.2f2
Firebase 5.0.0

I am working on Mac OS 10.13.x with Unity 2018, Visual Studio for Mac. I am using the Database and authentication.
Also, the project is under .NET 4.x, mostly for the "await" keyword.

Had another editor crash. Details: I was running my app, edited a script in visual studio and saved, switched back to unity which kicked off a compile (as normal), and I thought I had clicked the Play button to stop my app. Editor crashed after a few seconds. The editor log has same Firebase initializing log entries right before the crash info. See attached.
Editor.log

@marcz88 and @criistii we've been looking into this issue and have at least identified and fixed one issue. The "Firebase Services" MonoBehaviour (we use it to pump a job queue on the main thread) ends up pointing at a deleted object when the editor is running and recompilation occurs. This can end up in a NullReferenceException but not really a crash AFAIK.

The other issue @marcz88 referenced where the editor crashes and there are multiple app initializations in the log, it makes me wonder whether you're initializing Firebase on the main thread? If you're not then we'll run into all sorts of issues with job scheduling.

We think the 5.1.0 release of the Firebase Unity SDK resolves this issue:
Release notes: https://firebase.google.com/support/release-notes/unity#5.1.0
Download: https://firebase.google.com/docs/unity/setup

Please give it a try and reopen the issue if you're still running into problems.

Hi guys, apologies for the long delay in responding. I shifted focus on the project, then went on a vacation. I upgraded to 5.1.0 last week, and I was holding my breath for about 3 days because didn't see any editor crashes. But yesterday and today have experienced 4 crashes, all that happened immediately after log entries similar to:

thread_suspend failed
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).
Firebase App initializing app __FIRAPP_DEFAULT (default 1).

One unique thing about the crashes, they all have the "thread_suspend failed". I don't see this entry anywhere else in the logs. Is that a firebase log entry, and if so does that give you any clues? Thx

Hi @marcz88,

Are you getting any different native call stack when this crash happens? Or is it similar to the one you reported earlier? If it's any different, could you post an updated log file and stack trace?

Also could you verify whether the crash still happens in the latest Firebase Unity release (5.2.0) and if there are any reliable repro steps?

Thanks!

Jon

It's still happening pretty consistently with 5.1.0, about 1 editor crash every 10 times I click the play button. Sometime happens when I stop. The stack traces appear to be in the garbage collection, during scene load/unloads. I'll try out 5.2.0 and if I continue getting crashes, I'll collect a bunch of logs and send them for comparison. Thx for your help.

Thanks. BTW, did you see @stewartmiles' comment above about not initializing Firebase on other threads (only on the main thread)?

Also, are you keeping a reference to the Firebase objects (FirebaseApp, FirebaseAuth, FirebaseDatabase, FirebaseStorage, etc.) or just using DefaultInstance each time?

Finally, could you confirm which specific Firebase plugins you are using? (Auth, Database, Analytics, etc.)

Thanks again!

Jon

Regarding initializing Firebase on the main thread: I'm not initializing Firebase myself, just accessing the default instance like I've seen in other examples. I'm only using Messaging. I have a class called Notification derived from MonoBehavior that registers for MessageReceived and TokenReceived as below:

        void Start()
        {
#if UNITY_ANDROID || UNITY_IOS
            Debug.Log("Setting up Firebase messaging event handlers...");
            Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
#if UNITY_ANDROID
            Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
#endif
#endif
        }

with handler functions for OnMessageReceived() and OnTokenReceived(). Is there anything wrong with doing it this way?

I'm also integrated with AWS SDK for database, lambda and messaging. I'm using Firebase to receive messages and tokens on my iOS and Android clients in a unified way, and using AWS SDK to create topics, subscribe to topics so my lambda functions can use AWS SNS to notify clients of important data changes. Any possible issues with doing this?

Firebase Unity will lazily initialize things the first time they are accessed, so that will initialize FirebaseApp and FirebaseMessaging inside the Start() which I think should be fine, unless there's some way that's running from a different thread.

I'll delve into this a bit more, but definitely send along some logs if you can get them.

Oh, one small suggestion. Does it help if you hold onto a reference to Firebase.Messaging.FirebaseMessaging somewhere in your code? I am concerned that the Firebase.Messaging.FirebaseMessaging object may be getting garbage-collected. Just grab the reference and keep it somewhere that stays in memory for the duration of your app. Let me know if that workaround makes a difference.

I can try it, but not exactly sure how to hold a reference to Firebase.Messaging.FirebaseMessaging. I don’t see a way to get the instance to this. Do you mean FirebaseApp? if so, I see a GetInstance(string name), but don’t see the documented GetInstance() function (the one without the name parameter). Can you elaborate? Thx

On Aug 9, 2018, at 9:17 PM, jonsimantov notifications@github.com wrote:

Oh, one small suggestion. Does it help if you hold onto a reference to Firebase.Messaging.FirebaseMessaging somewhere in your code? I am concerned that the Firebase.Messaging.FirebaseMessaging object may be getting garbage-collected. Just grab the reference and keep it somewhere that stays in memory for the duration of your app. Let me know if that workaround makes a difference.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-unity/issues/160#issuecomment-411945855, or mute the thread https://github.com/notifications/unsubscribe-auth/ASomSUTtdlXKg3kUa7KoylFs8i91kzpqks5uPN8VgaJpZM4TqM3Z.

Sorry, I meant the FirebaseApp.DefaultInstance. Sorry.

Hi,

I've been looking deeper into this and have tested a minimal sample with scene transitions, and I'm still having trouble reproducing the crash, so I need a little more information:

  • You're registering the event listeners in Start(). Where are you un-registering the event listeners? Are you registering and unregistering them in every scene or just one time?
  • Are you accessing any of Firebase in any other part of your code besides these event registrations / unregistrations? Are you holding onto any objects you receive in the event handlers (the MessageReceivedEventArgs or TokenReceivedEventArgs)?
  • Have you tried running with Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug to see if anything else is logged?

Thanks,

Jon

  • I'm actually not unregistering the events because my app only has one scene. But I can try unregistering the events in OnDestroy().
  • I'm only accessing Firebase from one class where I'm register the event handlers in Start(). In the event handlers, I'm accessing the passed in parameters directly, not keeping a reference to any. The only thing I'm retaining is the device token string as I understand this is doing a string copy, not keeping a reference.
  • I'll try upping the loglevel
    Also, as suggested, I've added code to keep a reference to the DefaultInstance, however, I'm clearing the reference in OnDestroy().

I'll let you know how it goes.
Thx

After making the suggested changes, things have gotten much better. I didn't see a crash for quite a while but was holding my breath because I've seen this issue suddenly go away for a few days then reappear. That said I had editor crash when I turned the Play button off. I took a look at the log since I enabled Firebase debugging and I noticed something peculiar. It looks like Firebase is shutting down then trying to restart immediately, and it happens multiple times during the stop until it finally crashes. Check out the attached log.
Editor-crash-onstop.txt

Thanks, I'll take a look at the log and get back to you. I do see what you're talking about with it re-initializing Firebase App briefly before tearing it down again, very odd.

A few more questions:
Are you clearing the DefaultInstance before or after unregistering the message event listeners?
Do you have multiple Firebase packages added to your project or did you only import FirebaseMessaging.unitypackage?

I only imported one package, the FirebaseMessaging.unitypackage.

Here is the only Firebase related code in my app:

        // Use this for initialization
        void Start()
        {
#if UNITY_ANDROID || UNITY_IOS
            Debug.Log("Setting up Firebase messaging event handlers...");

            firebase = Firebase.FirebaseApp.DefaultInstance;
            Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug;
            Debug.Log("Firebase:" + firebase.Name + " MessageSenderId=" + firebase.Options.MessageSenderId.ToString());

            Firebase.Messaging.FirebaseMessaging.MessageReceived += OnMessageReceived;
#if UNITY_ANDROID
            Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;
#endif
#endif
        }

        private void OnDestroy()
        {
#if UNITY_ANDROID || UNITY_IOS
            Debug.Log("Unregistering Firebase messaging event handlers...");

            Firebase.Messaging.FirebaseMessaging.MessageReceived -= OnMessageReceived;
#if UNITY_ANDROID
            Firebase.Messaging.FirebaseMessaging.TokenReceived -= OnTokenReceived;
#endif
            firebase = null;
#endif
        }

#if UNITY_ANDROID
        public void OnTokenReceived(object sender, Firebase.Messaging.TokenReceivedEventArgs token)
        {
            Debug.Log("Received Registration Token: " + token.Token);
            m_DeviceToken = token.Token;

            if (LoginAWS.getInstance().IsLoggedIn())
                Register(() => { Debug.Log("Notification.Register complete"); });
        }
#endif

#if UNITY_ANDROID || UNITY_IOS
        public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
        {
            UnityEngine.Debug.Log("Received a new message from: " + e.Message.From);
            if ((e.Message.Notification != null &&
                !e.Message.Notification.Equals("")) ||
                (e.Message.Data != null &&
                !e.Message.Data.Equals("")))
            {
                // if app has initialized and is logged in
                if (LoginAWS.getInstance().IsLoggedIn())
                    ProcessNotification(e.Message.Data);
            }
        }
#endif

Update! I removed the Firebase SDK completely and saw editor crashes. It appears to not be related to Firebase. I'm checking other plugins now to narrow it down. Apologies for the goose chase. Thx for your help.

I came across this issue looking for people suffering from crashes with .NET 4.6. I can confirm that it's unrelated to Firebase. Our project suffers from it too (not using Firebase). It seems to happen after scene loads:

Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff7884de3e __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff7898c150 pthread_kill + 333
2   libsystem_c.dylib               0x00007fff787aa312 abort + 127
3   libmonobdwgc-2.0.dylib          0x0000000137caa4b2 mono_handle_native_crash + 585
4   libsystem_platform.dylib        0x00007fff7897ff5a _sigtramp + 26
5   com.unity3d.UnityEditor5.x      0x000000010389f86e mdb_a85 + 417710
6   libsystem_c.dylib               0x00007fff787aa312 abort + 127
7   libmonobdwgc-2.0.dylib          0x0000000137e5331e GC_stop_world + 150
8   libmonobdwgc-2.0.dylib          0x0000000137e52a2e GC_stopped_mark + 62
9   libmonobdwgc-2.0.dylib          0x0000000137e5278a GC_try_to_collect_inner + 311
10  libmonobdwgc-2.0.dylib          0x0000000137e53ec9 GC_try_to_collect_general + 158
11  libmonobdwgc-2.0.dylib          0x0000000137e53f3e GC_gcollect + 13
12  com.unity3d.UnityEditor5.x      0x0000000100d14659 CleanupAfterLoad() + 297
13  com.unity3d.UnityEditor5.x      0x0000000100d4442d LoadSceneOperation::PlayerLoadSceneF

Same problem and its not Firebase. I wrote in the support, but they could not reproduce
https://fogbugz.unity3d.com/default.asp?1065755_8pnsa7l0c2otmsv9

We are expecting a fix to come out with 2018.2.8 next Friday. However, with that we are seeing a slightly different crash:

Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff6eaf5e3e __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff6ec34150 pthread_kill + 333
2   libsystem_c.dylib               0x00007fff6ea52312 abort + 127
3   com.unity3d.UnityEditor5.x      0x0000000100ffe041 HandleSignal(int, __siginfo*, void*) + 81
4   libmonobdwgc-2.0.dylib          0x0000000138439c15 mono_chain_signal + 79
5   libmonobdwgc-2.0.dylib          0x000000013830b85b mono_sigsegv_signal_handler + 414
6   libsystem_platform.dylib        0x00007fff6ec27f5a _sigtramp + 26
7   ???                             000000000000000000 0 + 0
8   libmonobdwgc-2.0.dylib          0x00000001385531b6 GC_mark_some + 476
9   libmonobdwgc-2.0.dylib          0x0000000138552a72 GC_stopped_mark + 146
10  libmonobdwgc-2.0.dylib          0x000000013855277a GC_try_to_collect_inner + 311
11  libmonobdwgc-2.0.dylib          0x0000000138553eb9 GC_try_to_collect_general + 158
12  libmonobdwgc-2.0.dylib          0x0000000138553f2e GC_gcollect + 13
13  com.unity3d.UnityEditor5.x      0x0000000100d157f9 CleanupAfterLoad() + 297
14  com.unity3d.UnityEditor5.x      0x0000000100d455cd LoadSceneOperation::PlayerLoadSceneFromThread() + 1053

Since it doesn't sounds like this is Firebase, I'm closing this issue. Please let us know if you see a Firebase DLL / shared library in a stack trace.

Was this page helpful?
0 / 5 - 0 ratings