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

Resolved Player Crashes on MacOS with Metal - OpenGL Runs Fine

Discussion in 'Editor & General Support' started by LuGus-Jan, Jan 4, 2023.

  1. LuGus-Jan

    LuGus-Jan

    Joined:
    Oct 3, 2016
    Posts:
    179
    We're in the process of rounding up an update for our game that runs on Windows, Mac and Linux systems. However, we're running into a bit of a snag when it comes to the Mac build where the player crashes hard when using the Metal rendering API. Even the Unity Crash Reporter fails to show up. All runs well in the editor on Mac, as well as in the player running OpenGL. It's just the player build with Metal that crashes.

    In the log file of the player, we sometimes see the following lines happening, without a stacktrace:

    and

    Some of these lines were visible while running it in editor as well, and those that were found have been resolved (these were related to certain web requests not being disposed of properly). However, these are not visible anymore in editor, but do still popup in the player. So there's a difference in behavior there already.

    The game can be played for a little while, even with the above errors, but mostly crashes soon after, with an error printed our like the following:

    The last few lines of the stracktrace can differ between crashes, but the first four (mono_breakpoint_clean_code, mono_unity_backtrace_from_context, mono_jit_set_domain and libsystem_platform.dylib : _sigtramp) are consistently the same.

    I've tried to create a debug build with XCode project files, but that one doesn't even get to starting up where it breaks on the memory initializer. Not sure if there's anything of value to find there.

    When the player crashes, it also leaves a mono dump next to the .app file. Also not sure if there's any valuable information to find in there, or how to open it up to extract the relevant information.

    Some details about the project:
    - Currently running on Unity 2021.3.16f1. Upgraded recently from 2020.3.18f1.
    - The behavior is also seen on 2021.3.15 and 2022.2.1.
    - Using the built-in rendering pipeline (it's a project from 2015 - Unity 4.x era that we've been updating over the years, so no URP or HDRP)
    - Running it on a Macbook Pro 14" 2021 with M1, both the editor and the player.
    - Using just OpenGL as a rendering backend is not an option as it's not available for Apple Silicon native builds.

    Any ideas at what to look at, or how to extract information where we can start looking to what is the root cause of this?

    Thanks in advance!
     
    gsylvain likes this.
  2. gsylvain

    gsylvain

    Joined:
    Aug 6, 2014
    Posts:
    100
    We're experiencing a similar issue. Using 2021.3.14f1, URP 12.1.8, works fine on PC and Android. The bug only occurs on iOS builds, where it seems to randomly crash early during the gameplay. We don't have a clue aside from the same stack as above:

    Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak
    Invalid memory pointer was detected in ThreadsafeLinearAllocator::Deallocate!

    Our game code doesn't use any job or ECS stuff, so i'm assuming that this is coming from unity.
     
  3. LuGus-Jan

    LuGus-Jan

    Joined:
    Oct 3, 2016
    Posts:
    179
    @gsylvain

    We just resolved our issues. On our end, the crashing was caused by the 'Graphics jobs' option in the player settings when using Metal. So disabling that resolved our crash issue. Note that this setting does not seem to be shared by the target platforms. In our editor on Windows, when disabling that setting did not disable it for MacOS or iOS. I had to disable it in the editor on my mac for it go through (or manually adjust the player settings asset file).

    Yesterday we also found our cause for the memory leak warning. This was caused by performing
    Graphics.RenderMeshPrimitives
    or
    Graphics.DrawMeshInstancedProcedural
    on a camera that was disabled or inactive. Perhaps you might run into something similar on your end.

    Hope any of this helps in overcoming your issues.
     
    gsylvain likes this.
  4. gsylvain

    gsylvain

    Joined:
    Aug 6, 2014
    Posts:
    100
    Wow thank you for this. We just ran some quick tests and it seems stable now!
     
    LuGus-Jan likes this.
  5. EminemJ

    EminemJ

    Joined:
    Mar 10, 2020
    Posts:
    45
    Same here. Disabling GraphicsJobs on IOS will solve this issue(with Unity 2021.3.13f). But this is kind of weird, in our last project, we turned on GraphicsJobs on IOS and it works well with no issues(with unity 2019.4.31f). I guess there may be some graphics-related bug deep inside, and we triggered it somehow in our current project.
     
    gsylvain likes this.