Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

No monotonic clock on IL2CPP

Discussion in 'Scripting' started by Deleted User, Jul 12, 2018.

  1. Deleted User

    Deleted User

    Guest

    On all platforms, `System.Diagnostics.Stopwatch` is monotonic except on IOS(IL2CPP). It's supposed to measure the passage of time based on CPU clock, not on the system RTC.



    top: StopWatch class
    bottom: Time.time

    Clearly, this is a bug but it's Unity we're talking about here. They're never gonna fix this kind of bug. I didn't even try to file a bug report. Just be careful when using code copied from regular C# programs.
     

    Attached Files:

  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Well you can be sure they are never going to fix it if it isn't reported.

    According to the below link, some versions of StopWatch will use gettimeofday or DateTime.UtcNow.Ticks under certain circumstances, which I believe behave exactly how you've demonstrated. No idea what the code looks like as implemented with IL2CPP on IOS, but I wouldn't be surprised if that is what they are doing.

    https://aakinshin.net/blog/post/stopwatch/
     
  3. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Yeah I think you should definitely report this bug. The stopwatch is useful for performance timing so I'm sure they would want to fix it. They've always been responsive when I've reported bugs.

    Sam
     
  4. alesrazym

    alesrazym

    Joined:
    May 11, 2018
    Posts:
    17