Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mathf.Approximately failing on SteamOS

Discussion in 'Linux' started by CharlotteSutherland, Jul 6, 2022.

  1. CharlotteSutherland

    CharlotteSutherland

    Joined:
    Sep 22, 2016
    Posts:
    2
    Hi,

    My Linux build runs fine under Ubuntu, but is failing in odd ways when running on Steam Deck. After some digging, I've narrowed down one issue to Mathf.Approximately seemingly always returning false when running on Steam Deck.

    As an example, this code produces debug output when run on Steam Deck:

    Code (CSharp):
    1. float testFloat = 0f;
    2. if (!Mathf.Approximately(testFloat, 0f))
    3. {
    4.     Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, "0 is not approximately 0!");
    5. }
    Running the exact same build on Ubuntu, I get no output (and, similarly, I don't see this problem on Windows or console platform).

    I'm at a bit of a loss what to do about this. Has anybody seen anything similar or have any suggestions?

    Probably worth noting that the game also hangs on exit on Steam Deck (again, fine on other platforms, and the same build exits cleanly on Ubuntu).

    I see the same problem with both Mono and il2cpp Linux builds. This is with Unity 2020.3, but I've tried the newer LTS version with the same results.
     
  2. ChiwTheNeko

    ChiwTheNeko

    Joined:
    Mar 24, 2022
    Posts:
    108
    Did you try replacing Approximately by
    Code (CSharp):
    1. if (Mathf.Abs(testFloat - 0f) > Mathf.Epsilon)
    or
    Code (CSharp):
    1. if (Mathf.Abs(testFloat -0f) > 0.000001f)
    ?

    The implementation of Approximately is a bit weird. I'm sure there is a good reason for it but I don't know what that is. Maybe SteamOS libs are compiled with different floating point options and this is what's causing the issue, just a guess.
     
  3. CharlotteSutherland

    CharlotteSutherland

    Joined:
    Sep 22, 2016
    Posts:
    2
    Thanks, yeah, I did that to fix one specific case but unfortunately Mathf.Approximately is used pretty heavily in an asset I'm relying on.

    I might have to write a replacement function and do a big search and replace. Though I'm concerned that if this is broken, other things might be too. The hang on exit is also a bit worrying.

    Going to try to make a minimal repro case to see if it happens in a blank project.