I have an issue with firebase 1.1.0 for Unity SDK.
As soon as I activate firebase by FirebaseApp.DefaultInstance.SetEditorDatabaseUrl( myurl ) all Tasks not generated by firebase are executed on the main thread.
So I can retrieve and post data to firebase just fine and even process it in tasks. They run on separate thread, which I see when debugging. However when I will use Task.Run( MyComputingFunction ) in the Start method of some MonoBehaviour the Unity hangs. Assume that this function just counts from 0 to 999999 so it is not a locking problem. For the time of calculation Unity freezes because the task is executed on the main thread. If I will comment out firebase activation my task will run in separate thread and will not freeze Unity.
Please help.
Here is a minimal working example. Attach it to a game object and observe tasks running parallel. Uncomment pointed line and tasks will execute in linear order.
using UnityEngine;
using System;
using System.Threading.Tasks;
using Firebase.Unity.Editor;
using Firebase.Database;
public class NetworkController : MonoBehaviour
{
public static DatabaseReference @ref;
void Start()
{
// Uncomment line below
//InitializeDatabase();
TestStuff();
}
private void TestStuff()
{
Task.Run( Counter(1) );
Task.Run( Counter(2) );
Task.Run( Counter(3) );
}
private Action Counter( int i )
{
return delegate {
int a = 0;
while ( a + 10 < 900000 ) {
a++;
if ( a % 5000 == 0 )
Debug.Log( a + i);
}
};
}
private void InitializeDatabase()
{
Firebase.FirebaseApp.DefaultInstance.SetEditorDatabaseUrl( "https://dinosaur-facts.firebaseio.com/" );
@ref = FirebaseDatabase.DefaultInstance.RootReference;
}
}