Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feedback Crash when going to the next scene with .NET 4.x, but not with .NET 3.5

Discussion in 'Experimental Scripting Previews' started by Gladyon, Jun 8, 2019.

  1. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    389
    There is a major problem with the scene management in .NET 4.x.
    The following line of code is crashing 100% of the time (release or editor):
    Code (CSharp):
    1. SceneManager.LoadSceneAsync("EmptyScene", LoadSceneMode.Single);
    Of course, there's a bit more to that, here is the real culprit:
    Code (CSharp):
    1. m_AllData = new Toto[NbBatches][][];
    2. for (int i=0; i<NbBatches; i++)
    3. {
    4.     m_AllData[i] = new Toto[NbBlocks][];
    5.     for (int j=0; j<NbBlocks; j++)
    6.     {
    7.         m_AllData[i][j] = new Toto[BlockSize];
    8.     }
    9. }
    With 'NbBatches', 'NbBlocks' and 'BlockSize' are all set to 128 and 'Toto' being defined as:
    Code (CSharp):
    1. class Toto
    2. {
    3. }
    If that (mostly harmless) code is executed before loading the next scene, then loading the scene will crash.
    If there's no more scene loading during the life of the application, then there's no crash.

    It works perfectly well with .NET 3.5, but now that it will be removed it may be a major problem, because in my book, allocating a 3-dimensions array of 128x128x128 references (the objects aren't even instantiated!) should work.


    Note that 'm_AllData' must be a static field in order to produce the crash, a local variable or an instance field will not result in a crash.
    Also, it must be defined as:
    Code (CSharp):
    1. static private Toto[][][] m_AllData;
    Because the following will not crash:
    Code (CSharp):
    1. static private Toto[,,] m_AllData;

    The bug report reference is 1161315.
    You will also find a very tiny project attached to that post, which reproduce the problem 100% of the time with only 19 lines of code (according to Visual Studio).
    The project has been created with Unity 2018.3.0f2 but any Unity version with .NET 4.x will crash.


    So, my feedback is: please keep .NET 3.5 until that bug is fixed, being able to allocate an array of reference is quite important for most projects.
     

    Attached Files:

  2. joncham

    joncham

    Unity Technologies

    Joined:
    Dec 1, 2011
    Posts:
    276
  3. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    389
    Thanks for the info.
    I'm not sure it's the same bug, as mine can be reproduced with 2017 and 2018 versions.
    But they do seem to be quite close, so maybe the root cause is the same.

    That would be great when this fix will be available in 2018.4, and mostly in 2017.4 because it's one of the last version with the old networking stack, and it's out of a question to rewrite the networking part of a very large game at this point.


    Also, for information, in my test project the crash occur with an array of type [][][], but the problem is exactly the same with similar data structure such as a Dictionary<int, Dictionary<int, Dictionary<int, Toto>>> with wash Dictionary instantiated with 128 elements.
    I also tried with List<Stack<Array[]>>, and the problem also occur, probably because all these collections are using an array in order to store the data.
     
  4. Gladyon

    Gladyon

    Joined:
    Sep 10, 2015
    Posts:
    389
    For information, it was the same bug as 1137077.
    I have checked with Unity 2019.3.0a7 and I can confirm that the bug is indeed fixed.

    My thanks to the Unity team.