Search Unity

2D Physics inconsistency when updating OnePlus 3T/Samsung J6 to Android 9

Discussion in 'Physics' started by Menion-Leah, Jul 16, 2019.

  1. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    The mobile game we're developing strongly relies on 2D Phyisics determinism.

    During the last years of work, we managed to get a fully working simulation when targeting same architecture and running the same build (IE: ARM 32 build runs in a consistent way on all ARM 32bit or 64bit devices; x86 build on every Android phone with Intel processor, and so on).

    We recently updated one of our test devices, a OnePlus 3T, from Android 8 to Android 9. From that moment on, physics consistency has been impossible to achieve on that device. We tried building 32 bit, 64 bit, Mono, IL2CPP, setting Maximum Api Level to 8.0, nothing worked.

    It's worth noting that:
    - that OnePlus3T phone was working correctly before the OS update (thousands of simulations); after the update, same build and same connected devices always fail to run a consistent simulation
    - we tested another phone running Android 9 (an Honor View 10) and it's working perfectly

    We developed a simple repro to highlight how this new issue is surely due to Unity 2D engine being handled in a different way by OnePlus3T running last Android update (Android 9, OxygenOS 9.0.4):

    >> REPRO <<

    STEPS TO REPRODUCE:
    - build attached project for ARM32 IL2CPP or ARM64 IL2CPP or ARM32 Mono, or use provided .apk
    - run the simulation on a OnePlus 3T running on Android 9, and wait a couple of minutes for the physics to stop
    - run the simulation other ARM-based phones, including OnePlus 3T running Android 8 or previous
    - notice how simulation results differ for OnePlus 3T with Android 9 only

    Is anybody experiencing this same issue?


    This is the correct simulation outcome:

    Screenshot_20190716-162949.png


    And this is the wrong simulation outcome, on OnePlus3T with Android 9:

    Screenshot_20190716-164514.jpg


    Update

    We just updated a Galaxy J6 to Android 9 as well, and it's giving the same identical behavior than the updated OnePlus 3T (second picture).

    Now they both give the same simulation results, that differ from the one produced by all the other devices (and the one they gave before updating to Android 9).

    Looks like this update totally changed the way in which floating point calculations are made.
     
    Last edited: Jul 17, 2019
  2. felchs

    felchs

    Joined:
    Jul 16, 2019
    Posts:
    21
    The 2D Physics of Unity is not deterministic because it uses Box2D:

    https://support.unity3d.com/hc/en-us/articles/360015178512-Determinism-with-2D-Physicshttps://support.unity3d.com/hc/en-us/articles/360015178512-Determinism-with-2D-Physics

    However, for your application, you might want strict determinism. As such, you would need to know whether Box2D can produce identical results on different binaries and different platforms.

    Generally, Box2D cannot do this. The reason is that different compilers and different processors implement floating point math differently, which affects the results of the simulation.

    Box2D can only produce determinism in the same architecture with some restrictions recreating the scene, positions etc... as It is said on the article. So 2D Physics of Unity in 16/JUL/2019 is not deterministic.
     
  3. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189

    Please, read and understand the original post before replying.

    I'm already aware of the limitations of Box2D and its Unity derivation; despite that, by providing the same build to the same CPU architecture you can obtain full determinism.
    That's what we already achieved.

    Also, the same OnePlus 3T that now, after OS update to Android 9, is not able to run a single consistent simulation, has already run thousands and thousands of simulations in the last 2 years and half, all behaving in a consistent manner.

    If you don't trust my words, just download provided .zip file, install .apk on an Android/ARM phone, run it and watch the outcome to be exactly identical as the one in the first picture.


    Also, the statement you provided confirm what I am saying: under same architecture and build, and taking into account some restrictions and workarounds, you can make it behave in a deterministic way.
     
    Last edited: Jul 16, 2019
  4. felchs

    felchs

    Joined:
    Jul 16, 2019
    Posts:
    21
    I'm sorry I didn't read your post correctly.

    So this update ruined your determinism.

    Is it in java? Maybe the Box2D run in Java? Normally the strictfp is used to handle determinism on floating point in java.
    Maybe this OnePlus3T update generated a build which removed this feature?
    Just wondering...
     
  5. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    Yes, you got the point. Unfortunately, I fear this isn't something we developer can handle.. I suspect only Unity can fix it on its side, or advise OxygenOS to do it.

    Given that the issue reside directly in the 2D Physics engine, I suppose it should be running in a compiled C++ unity library.
    The only thing I could suspect, is that this new OxygenOS release is somehow wrapping Unity player into another emulation-like layer: I experienced similar behaviors when running ARM builds in a PC emulator or on a x86 Android phone. :/
     
  6. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    Update

    We just updated a Galaxy J6 to Android 9 as well, and it's giving the same identical behavior than the updated OnePlus 3T.

    Now they both give the same simulation results, that differ from the one produced by all the other devices (and the one they gave before updating to Android 9).

    Looks like this update totally changed the way in which floating point calculations are made.
     
  7. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    Update
    My bug report has been reproduced and forwarded to Unity developers, but several weeks passed without any answer.
    Meanwhile, we reached a broader audience (we soft-launched the game) and discovered that there's another class of devices that produce a different outcome for the simulation: it's some Samsung J6 phones, probably updated to another Android version.

    This is getting very problematic for us, as it's segmenting the userbase (and it's a multiplayer game, so..).
    We feel helpless since it's something that ultimately depends on Unity/Android interaction and we cannot do anything about it.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    There's no platform specific code in the 2D physics engine at all so no idea what is going on here. If there's some fundamental floating-point handling issue then it's nothing that the 2D physics system can do.

    What is the case number for the bug report? I've certainly not seen it.
     
    Menion-Leah likes this.
  9. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    Hi @MelvMay
    Thanks for your quick answer.

    Case # is 1169979.
     
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    This case is assigned to one of the mobile teams which sounds correct to me as this isn't something specific to 2D physics by the look of it. All I can do is ping them about it but beyond that there's not much I can do.
     
    Menion-Leah likes this.
  11. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    Thank you very much, @MelvMay

    Is there any public link I can access to follow its progress?
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    Menion-Leah likes this.
  13. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    Thank you!!!
     
  14. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    More than 6 months passed, still no updates.

    Is there at least any hope that a new DOTS-based 2D physics engine will be released as an alternative to the current one?
     
  15. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    That bug is still sitting with the android team as it has nothing to do with 2D physics. Very little I can do beyond pinging them.
     
  16. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    Sure, that's clear, and thank you for your help, @MelvMay .

    I was hoping to understand if there's any plan to release a DOTS-based 2D engine along with the 3D one: that would (theoretically) offer another solution to this issue, and also providing a cross-platform determinism.
     
  17. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    Which kind of contradicts the previous statement because the physics system has no platform specific code in it so it wouldn't solve this. It's not even clear what is going wrong on Android and I can only think of fixed-update timings being screwed.

    That wouldn't be solved by the physics system either, it'll be solved by the floating-point cross platform support; something which the DOTS team are working on. The native 2D physics (Box2D) would be deterministic if it were not for that.

    Yes, that's being worked on.
     
  18. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    Sure, I totally understand that physics system has no platform specific code in it.

    What I meant is that since current Box2D engine relies on floating-points calculations that grants no cross platform consistency, and since with this bug I'm currently seeing a behaviour very similar to the one you can face when building for different architectures (IE arm32 VS arm64), maybe by using another 2D engine that relies cross platform floating-point support would work (that's why I used theoretically in the previous sentence).

    If there were any plan to modify Unity's current Box2D engine to take advantage of DOTS, it would be simply great.


    That's excellent news, thank you! :D
     
  19. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    After almost 2 years, the Issue has been closed with a "BY DESIGN" statement.

    Awesome, having hardware upgrades breaking compatibility is now "by design" (and it took only 2 years to realize that).

    I'm on 2019 LTS and still I face HUGE issues with every new release - just to mention a couple of them, that apply to all 4 different projects I'm working on:
    - compile time with IL2CPP went from 3-5 minutes to 60-90 minutes, since two months ago
    - upgrading to 2019.4.21f1+ breaks every prefab connection (and Unity answer is Won't fix)

    Features like the ones mentioned in this thread (cross-platform physical engine) that have been promised in 2018 are still out of any radar (and surely not happening in 2021).

    I work with Unity since 2012, I also teach it since 2018, but I'm seriously thinking about giving up.
     
    PutridEx likes this.