GithubHelp home page GithubHelp logo

Unity editor rounds down floats to integers when retrieved from realtime database when locale is not en_US.utf8 about firebase-unity-sdk HOT 21 CLOSED

firebase avatar firebase commented on May 23, 2024
Unity editor rounds down floats to integers when retrieved from realtime database when locale is not en_US.utf8

from firebase-unity-sdk.

Comments (21)

muflub avatar muflub commented on May 23, 2024

Hi @Havard-SL,

I tested this using C++ library on desktop, Unity library on desktop and Unity library on Android and got the same output each time for my test: DataSnapshot { key = test, value = 3.14156 }.

image

Are you able to provide a screen shot of your firebase database console showing the data you have?
Are you able to use GetRawJsonValue and dump the correct value in json?

Edit: One thing to note is I was using the latest release 6.7.0 and not 6.6.0.
Edit 2: Can you please turn on verbose logging and check to see what value is sent on the wire.

Add this to the start of the start function:

        FirebaseApp.LogLevel = LogLevel.Verbose;
        FirebaseDatabase.DefaultInstance.LogLevel = LogLevel.Verbose;

Should see this log line:

[pc_0] handleServerMessage d {"d":2.69,"p":"test"}

from firebase-unity-sdk.

Havard-SL avatar Havard-SL commented on May 23, 2024

Thank you for your quick response, and sorry for my slow response!

First of all, I updated my firebase SDK to version 6.7.0, but the issue still persisted.

I am not sure if I implemented it correctly but GetRawJsonValue just gave me "2" in the debug log,

And lastly, weirdly enough, the log line I got was reading:

[pc_4] handleServerMessage d {"d":2,"p":"test"}

Thank you for trying to help me, I really appreciate it!

from firebase-unity-sdk.

muflub avatar muflub commented on May 23, 2024

That message you replied with is the raw response Firebase gets over the wire. Thus it looks like the data stored in Firebase real time database is an integer not a double and thus not a problem with the SDK. Please check the logic you use to save the values and ensure types are correct for storing floating point numbers (should be using double).

from firebase-unity-sdk.

Havard-SL avatar Havard-SL commented on May 23, 2024

I have attached a picture of my firebase realtime database and unity side by side:
bilde

Here you can see that I have stored the variable as a float, and my only database rules are:

{
  "rules": {
    ".read": true,
    ".write": false
  }
}

I have no clue why this happens, any help would be appreciated!

from firebase-unity-sdk.

alexames avatar alexames commented on May 23, 2024

from firebase-unity-sdk.

chkuang-g avatar chkuang-g commented on May 23, 2024

Hi @Havard-SL

Could you provide more logs? Yo can find your Editor log here
https://docs.unity3d.com/Manual/LogFiles.html

Also, the snippet of code about how you call into database API would be very helpful.

Here is what I read from your screenshot.
There is a mysterious request 1 sent before the listen request.
Then there is a listen request 2
And the response for mysterious request 1 is received with value 2 at "test". This seems to trigger the listener with value 2 and removed the listen id.
When response for request 2 is received, it cannot do anything. And I cannot see what the actual response message is from your screenshot.

I suspect you might have done something like but I cannot confirm with your screenshot.

ref.SetValueAsync(2);
ref.GetValueAsync().ContinueWith(task => {
  Debug.Log(task.Result);
});

So, please provide more information. Thank you!

from firebase-unity-sdk.

google-oss-bot avatar google-oss-bot commented on May 23, 2024

Hey @Havard-SL. We need more information to resolve this issue but there hasn't been an update in 7 days. I'm marking the issue as stale and if there are no new updates in the next 3 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!

from firebase-unity-sdk.

Havard-SL avatar Havard-SL commented on May 23, 2024

I am extremely sorry for the late response, but thank you all for trying to help!

I've been busy studying for a final, so I had to focus on some other things, but I would be happy to answer any questions now!!

@chkuang-g Ive made a gist of my Editor.log placed in my ~/.config/unity3d/ folder:
https://gist.github.com/Havard-SL/c7fa8d760ec403c4373c6315af63815f

The current code I'm using to access the realtime database right now is almost the same as the one in my original issue description:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using Firebase;
using Firebase.Unity.Editor;
using Firebase.Database;


public class test: MonoBehaviour {
  void Start() {
    FirebaseApp.LogLevel = LogLevel.Verbose;
    FirebaseDatabase.DefaultInstance.LogLevel = LogLevel.Verbose;

    // Set thistask before calling into the realtime database.
    FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://unity-test-9f7cc.firebaseio.com/");
    
    DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;
    Debug.Log("Aigt imma head in");
      FirebaseDatabase.DefaultInstance
      .GetReference("test")
      .GetValueAsync().ContinueWith(task => {
        if (task.IsFaulted) {
          // Handle the error...
          Debug.Log("Error");
        }
        else if (task.IsCompleted) {
          DataSnapshot snapshot = task.Result;
          // Do something with snapshot...
          Debug.Log(snapshot.GetRawJsonValue());
        }
      });
  }
}

This is almost directly copied from the Unity firebase starter guide, but including all changes people have suggested here.

If you want more screenshots I would be happy to share, but I dont know what part of the console output contains the relevant information!

I am very grateful for your help!
-Håvard

from firebase-unity-sdk.

google-oss-bot avatar google-oss-bot commented on May 23, 2024

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

@Havard-SL 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.

from firebase-unity-sdk.

chkuang-g avatar chkuang-g commented on May 23, 2024

@Havard-SL

This is definitely odd.

For what it worth, we actually fixed whole load of database editor issues in 6.7.0. Also 6.8.0 is out too.
https://firebase.google.com/support/release-notes/unity#version_670_-_november_13_2019

Could you try to download the latest version and see if that fixed your issue?

Also, I'll try to run your code with 6.6.0 next week and see what I can find.

Shawn

from firebase-unity-sdk.

Havard-SL avatar Havard-SL commented on May 23, 2024

@chkuang-g

Thank you for informing me of the new update. However, it did not work. On the contrary I get two new errors:

Error: Could not load signature of Firebase.Editor.XcodeProjectModifier:get_Project due to: Could not load file or assembly 'UnityEditor.iOS.Extensions.Xcode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. assembly:UnityEditor.iOS.Extensions.Xcode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null type:<unknown type> member:(null) signature:<none>

But as I'm not testing or planning to build this on iPhone, this is most likely irrelevant.
The other one:

Unloading broken assembly Assets/Firebase/Editor/Firebase.Editor.dll, this assembly can cause crashes in the runtime

I have no clue what this means. I did not see these in any of the previous firebase sdk versions.
I just thought I should mention them in case they were relevant to this problem.

Something I haven't mentioned previously, but could be useful is that i didn't have this issue previously, but it appeared after a while. The only thing I can think of that could have made a difference is a rouge config (however, I have this issue on two different machines, so it would be unlikely, but still possible), or the messing around with libssl.1.0.2 to circumvent the above mentioned issues.

I work with a fellow student who runs arch linux, but he does not have this problem, on the other hand, since I run ubuntu, there should be more bug reports similar to mine, as it is a more popular distrobution.

Thank you for trying to help me!
-Håvard

from firebase-unity-sdk.

chkuang-g avatar chkuang-g commented on May 23, 2024

@Havard-SL

Oh boy, that looks like a regression in 6.8.0.

Could you try 6.7.0 and see if that is fixed?

Another question: I saw you were trying to set Editor Database Url
FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://unity-test-9f7cc.firebaseio.com/");

Is this different from the one from google-services.json?

I'm trying to reproduce this on Linux machine.

from firebase-unity-sdk.

chkuang-g avatar chkuang-g commented on May 23, 2024

Alright, tried to modify the quick-start , change UIHandler.cs to call GetValueAsync() like you did, imported 6.6.0, and ran on a Linux machine. Got a solid 2.69.

    // Initialize the Firebase database:
    protected virtual void InitializeFirebase() {
      FirebaseApp app = FirebaseApp.DefaultInstance;
      StartListener();
      isFirebaseInitialized = true;

      FirebaseApp.LogLevel = LogLevel.Verbose;
      FirebaseDatabase.DefaultInstance.LogLevel = LogLevel.Verbose;

      FirebaseDatabase.DefaultInstance
      .GetReference("test")
      .GetValueAsync().ContinueWith(task => {
        if (task.IsFaulted) {
          // Handle the error...
          Debug.Log("Error");
        }
        else if (task.IsCompleted) {
          DataSnapshot snapshot = task.Result;
          // Do something with snapshot...
          Debug.Log(snapshot.GetRawJsonValue());
        }
      });
    }

I really wonder if you were connected to the right database... 😂

Could you try to do the same with quickstart and add your google-services.json to the project as well?

Also, very curious, if you change the value to, say 7.77, do you get 7 as a integer on your client?

from firebase-unity-sdk.

Havard-SL avatar Havard-SL commented on May 23, 2024

Thank you for your response, @chkuang-g !

I have reinstalled my entire operating system (Still ubuntu 19.10) and launched unity hub using a flatpak, so that I don't have installed libssl 1.0.2 manually as mentioned before, and it just worked fine (except for the lowermost error you can see on the picture below).

I tried changing the value in the database to 7.77 as you said, and got 7 as my output!
bilde
I used the same code as I wrote in my original post, but I can try to change the example code, like you did if you want!

If I put quotation marks around the values, I get the correct response:
bilde

Thank you!

-Håvard

from firebase-unity-sdk.

chkuang-g avatar chkuang-g commented on May 23, 2024

I'll dig more about this issue with our RT DB backend.

At the meantime, in order to fix those error message you saw about "Unload broken assembly", we just release a patch 6.8.1 which should resolve that. Not really related to your original issue though.

from firebase-unity-sdk.

chkuang-g avatar chkuang-g commented on May 23, 2024

@Havard-SL

Happy new year and sorry for the late reply.

We had a hard time to reproduce the same issue on our Linux/Window/Mac machines. This seems to be an unique issue to your machine since no other people has reported the same issue yet. However, based on your log and our tests, we narrow down the potential place which was causing the issue.

Long story short, it does not seems to be a server issue but the problem when the client is parsing the data here.
https://github.com/firebase/firebase-cpp-sdk/blob/master/database/src/desktop/connection/connection.cc#L310

Since we cannot reproduce the issue, we would need your help to root the cause. And the first step is to confirm our assumption.

Could you download this custom build FirebaseDatabase plugin, import it, run your game and paste the log here?

You should see some logs start with "JsonToVariant:" and "FlexbufferToVariant:". Basically this custom build is just trying to log the message your editor received from the database server and print out the parsing process.

Thank you!
Shawn

from firebase-unity-sdk.

Havard-SL avatar Havard-SL commented on May 23, 2024

Happy new year, @chkuang-g ! And thank you for sticking to this issue!

I made a new gist of the Editor.log after trying the new DLL in a new clean project, as just copying the logs from inside the unity editor proved extremely cumbersome:
https://gist.github.com/Havard-SL/211f5e913c5061d0c047de911155f972

I have also noticed that at the top of the log it still says "No usable version of libssl found", which is kind of weird considering I am using unityhub from a flatpak and the project runs fine (except for the bug, of course)

On the positive side there are a ton of those JsonToVariant and FlexbufferToVariant, so at least I imported the DLL correctly!

Thank you so much for helping, and if there is anything else I can do to help please inform me! :)

from firebase-unity-sdk.

chkuang-g avatar chkuang-g commented on May 23, 2024

Hi @Havard-SL

Thanks for the log. This confirms that something is wrong during the parsing.
https://gist.github.com/Havard-SL/211f5e913c5061d0c047de911155f972#file-editor-log-L4562
https://gist.github.com/Havard-SL/211f5e913c5061d0c047de911155f972#file-editor-log-L4674

One thing we noticed was that it showed "7,000000" which uses comma instead of dot. I assume your machine's global locale is not "en_US.utf8". This might be the reason why the parser failed, since it is expecting a comma when parsing "7.77".

One potential fix could be setting the locale to ""en_US.UTF-8". Ex.
$ export LANG=en_US.utf8

You can use locale -a to check if the locale is supported.

At the meantime, we are trying to figure out how to make this independent from the locale.

Thanks for reporting this!
Shawn

from firebase-unity-sdk.

Havard-SL avatar Havard-SL commented on May 23, 2024

Thank you so much, @chkuang-g and everyone else who helped!

Using export LANG=en_US.utf8 fixed the issue, since my current LANG was nn_NO.UTF8

I would never have expeced that to be the issue, thank you so much for helping!

Should I leave this issue open until a permanent fix is pushed?

Again, thank you so much for all your help, you're doing an amazing job!
-Håvard

from firebase-unity-sdk.

chkuang-g avatar chkuang-g commented on May 23, 2024

Glad that it works for you.
Please leave this issue open. We will close it once we release a patch for this.

from firebase-unity-sdk.

cynthiajoan avatar cynthiajoan commented on May 23, 2024

This issue should be fixed in 8.7.0. Close for now and if it still appears, please reopen.

from firebase-unity-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.