0

How can I manually recreate a situation that will lead to the crash of the game on android? At the moment I'm testing the save system, and randomly once it happened to crash the game, because of which all my saves flew off.

Now I want to try to manually "break" the game in order to finalize the save system, any ideas? I only have stack overflows on my mind, but has anyone tried to do something like this before?

Gitenax
  • 9
  • 3
  • 2
    Why not [politely exit the app?](https://stackoverflow.com/questions/45636512/application-quit-wont-work-on-android) – gunr2171 May 04 '23 at 13:39
  • @gunr2171 op wants to test the robustness of their save stystem and make sure data is not corrupted through a crash, this is a reasonable use-case for trying to crash the app rather than "politely exiting" – Jay May 04 '23 at 18:13

1 Answers1

0

Obviously this is not something that Android wants you to do so there isn't a "correct" answer, but something as simple as

void Update()
{
    if(!shouldCrash)
        return;

    while(true)
        var _ = 0;
}

might work.

Unity is single threaded so this should hang the main thread, which Android may detect as a crash and kill your process. I am not sure if this is a gurentee though.

You could maybe also force a stackoverflow with

void Update()
{
    if(!shouldCrash)
        return;
    
    Span<long> a = stackalloc long[10_000_000]; // stupid big array for the stack
}

Allthogh i've never tried this and it may not work in unity

Jay
  • 2,553
  • 3
  • 17
  • 37