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

Can't get a clean Application.Quit() because of ComponentSystem NullRefs

Discussion in 'Entity Component System' started by daschatten, Feb 25, 2019.

  1. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    Hi,

    my game crahes on quit:

    I even tried to wait some time after disposing the world:

    Code (CSharp):
    1.  
    2. World.DisposeAllWorlds();
    3. yield return new WaitForSeconds(0.1f);
    4. Application.Quit();
    5.  
    Any ideas how to solve this?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    From memory you still need to update the game loop after disposing worlds. (not at pc I'll check shortly.)
     
  3. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    Why do i need to update the game loop after disposing worlds? Is it necessary only once after disposing?
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    Because you are disposing of all systems in the world but they are all still referenced by the loop.

    This is what unity does for their initialization system and you should mimic it.

    Code (CSharp):
    1. private static void DomainUnloadShutdown()
    2.         {
    3.             World.DisposeAllWorlds();
    4.  
    5.             // ...
    6.  
    7.             ScriptBehaviourUpdateOrder.UpdatePlayerLoop();
    8.         }
    9.  
    Code (CSharp):
    1. var world = new World("my world");
    2. World.Active = world;
    3.  
    4. //...
    5.  
    6. PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);
     
  5. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
  6. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    Have to correct myself... does not work either.

    As a workaround i do:

    Code (CSharp):
    1.  
    2.             World.DisposeAllWorlds();
    3.             ScriptBehaviourUpdateOrder.UpdatePlayerLoop();
    4.             Application.Quit();
    5.             if (!Application.isEditor) System.Diagnostics.Process.GetCurrentProcess().Kill();
    6.  
    No more errors in log or freezes :rolleyes:
     
  7. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    Out of interest, I assume the app still freezes on close when you updated to use ScriptBehaviourUpdateOrder.UpdatePlayerLoop();
    Do you get an error? If so it should be different than the previous one.

    I've noticed built applications sometimes freeze when closing (even when not using Application.Quit) and I haven't been able to pinpoint the issue.
     
  8. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    Nope, it's the same as before. I experience freezes with other games (without ECS), too. There are a lot of posts about a freeze on quit, but nothing helps. The most useful post mentioned killing the process, not great but works :)