Tests with the new Unity versions are ongoing and i will post updates here.
While still testing with the old stuff i could find the first possible reason for the crash.
I added three things to all npcs and the player.
- automatic movement
- automatic shooting
- auto camera rotation (player only)
and it crashed in roughly 5-10 min. with fps capped to 40 it took roughly 30 min.
Then i tried different combinations and noticed that it doesnt crash without firing.
Then i added game rules to increase the fire rate and i think it crashes a bit faster but not always. But sometimes after 20 sec with this.
It let the build without shooting run overnight (10 hours) and it didnt crash so i think something happens.
Sadly shooting triggers a huge amount of stuff so ill try to write down everything if someone has a guess.
- Shoot
- Fetch Projectile from Pool (Network Object) (Netcode for Gameobjects)
- Spawn Projectile in network (the crashes were observed in host and client/server mode)
- Store projectile in list
- Iterate over all projectiles and execute raycasts as a batch
- Wait until a later stage and evaluate raycasts in a for loop again
- Handle collision behaviour
- Trigger vfx and sfx based on collisions
My first guess was that it was problematic to spawn two projectiles in the same frame but this was not the case as i activated triple fire mode and spawned three projectiles in the same frame.
My other guess is the following. As the crash is always triggered by a thread accessing invalid memory that it is cost by the raycast commands.
I use raycast commands every frame for animations (all animations get grouped together and one batch is executed) and then of course the batching for the projectiles. The flaw with this guess is that in client mode the projectiles are not moved only the position is synced so the client does not execute raycasts.
So my current guess is some issue with maybe sound effects getting triggered at the same time. Because fmod uses threads and its also always in the stack trace. And i dont trigger as much one shot sounds from just driving but a lot get triggered from shooting and bullet impacts.
Summary:
- It crashes only when the players shoot (as for now)
- It has a tendency to crash faster with more shooting
- It does not crash with moving and camera rotation (so far after 10 hour test)
- It can crash when the player itself is not shooting (but maybe npc was shooting)
- It happens in offline host mode and in online client mode
- The server (linux server) does not crash only specific clients
- At this point it is not clear if every client crashed because of lacking crash reports
- Multiple raycast commands can be execute at the same time (but only in host mode)
- FMOD uses threads so maybe multiple sfx in one frame creates errors.
- The stack traces might be misleading as the crash is caused by a thread
Any ideas or help is appreciated for this. Ill continue updating stuff here.
Is it possible to catch memory access violations with try catch?