I couldn’t find other posts regarding this problem by searching so I wanted to ask the forum here to see if anyone may have an idea of whats happening.
The error is very simple, I open my built game on my Intel Mac, then I just swipe to another app (say, Google Chrome), and then I swipe back into the game and… it crashed. This has been reproducible in three different Macs.
I checked the game’s logs and there are no exceptions or errors popping up. I haven’t been able to find any code loops in my game (I searched besides knowing very well that there surely aren’t any). I have removed shady dependencies that may cause this error, but to no avail.
I was wondering if anyone may have any idea what this might be. Is there any callback function regarding “going into focus” of an application or something I might check? Are there some error logs I might check as well? I still need to try removing some dependencies to check if they might be the reason.
Also having this problem but on Apple Silicon. Built using 2022.3.24f1 IL2CPP
Edit: Same problem occurs when built with Mono
Swiping spaces, minimizing, or losing focus (swiping is the easiest way to crash it, but you can just click on another open window in the same space)
Nothing in logs. Nothing in Console.
Other similar forum posts have suggested enabling graphics jobs and disabling multi-threaded rendering. Neither of which helped.
I have also tried enabling/disabling Incremental GC. No effect.
Edit 2: This can be reproduced with a project built from the Unity 2D template (Core → 2D (Built-in Render Pipeline)
Make no changes to this project other than setting the build target to Apple Silicon. Click Build and Run. Swipe to change spaces. Swipe back again and the game will have crashed.
Yeah its really weird and inconsistent. For me, right now, the problem disappeared. But I can’t point at why honestly.
I have other games where the same issue happens, but in older versions it doesn’t happen. Again, nothing on console or logs. Really weird.
Similar problem on my MacBook Pro with M1 Pro chip, every time I switch to another desktop or a full screen application the build doesn’t give any type of response and I have to force quit.
Got a similar issue some time ago, not sure it will work in every case but if that helps, here is what I did :
I found out that in my case the issue was related to VSync being enabled and somehow messing with the game in the background, the simplest solution I found was to add a monobehaviour implementing the function “OnApplicationFocus” on a gameobject that has DontDestroyOnLoad attribute and automatically enable/disable VSync depending on wether or not the application is focused
Ok so, after the problem became so big it had to be solved, I did the first obvious thing which was to update from 2022.3.22f1 to 2022.3.37f1 and… Its working flawlessly.
It seems it was a bug from Unity’s side that was fixed between 22f1 and 37f1.
Regarding this. That was what I was going to try if updating Unity wouldn’t do it, since I’d seen in several places that the problem would arise from VSync. But of course Updating did it, so I’m not sure if handling VSync would’ve solved my problem or not. Thanks for the suggestion!
TL;DR:
Update Unity. I was lazy and didn’t update Unity. Dont be like me.