Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Crashing when loading new scene - AssignCookieToMaterial and ShaderPropertySheet::UpdateTextureInfo

Discussion in 'Windows' started by Wikzo-DK, Jan 7, 2020.

  1. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    78
    We are encountering a bug where the Windows executable crashes when loading from one scene to another. It only happens in a build.

    Looking at the crash dump file, the error seems to be related to light cookies. Maybe it doesn't unload correctly?

    Code (CSharp):
    1. Read from location FFFFFFFFFFFFFFFF caused an access violation.
    2.  
    3. Context:
    4. RDI:    0x00000163dd2329c0  RSI: 0x00000163b2dbeac8  RAX:   0x00007ffa1da75e58
    5. RBX:    0x0000000000000028  RCX: 0x00000163dd2329c0  RDX:   0x0000000000000000
    6. RIP:    0x00007ffa1cebfdbc  RBP: 0x00000163b2dbeac8  SegCs: 0x0000000000000033
    7. EFlags: 0x0000000000010206  RSP: 0x00000038c38dcf70  SegSs: 0x000000000000002b
    8. R8:     0x00000038c38dd060  R9:  0x00000163dd2329c0  R10:   0x0000016397f2e930
    9. R11:    0x00000163d19f1aa0  R12: 0x00000038c38dd060  R13:   0x00000163a46eaf80
    10. R14:    0x0000000000000000  R15: 0x00000163c57ca920
    11.  
    12.  
    13. Bytes at CS:EIP:
    14. ff 90 08 01 00 00 84 c0 0f 85 4e 01 00 00 8b 9c
    15.  
    16. Mono DLL loaded successfully at 'D:\Builds\TEMP\Crash_PDB_7-1-2020\MonoBleedingEdge\EmbedRuntime\mono-2.0-bdwgc.dll'.
    17.  
    18.  
    19. Stack Trace of Crashed Thread 22596:
    20. 0x00007FFA1CEBFDBC (UnityPlayer) ShaderPropertySheet::UpdateTextureInfo
    21. 0x00007FFA1CEBDF86 (UnityPlayer) Material::SetTexture
    22. 0x00007FFA1CD3A9C1 (UnityPlayer) AssignCookieToMaterial
    23. 0x00007FFA1CD31367 (UnityPlayer) RenderLightDeferred
    24. 0x00007FFA1CD32341 (UnityPlayer) DeferredRenderLoop::RenderLighting
    25. 0x00007FFA1CD2B8DB (UnityPlayer) DoDeferredRenderLoop
    26. 0x00007FFA1CD2C565 (UnityPlayer) DoRenderLoop
    27. 0x00007FFA1CCD464F (UnityPlayer) Camera::CustomRender
    28. 0x00007FFA1CCD9EB5 (UnityPlayer) RenderManager::RenderCameras
    29. 0x00007FFA1CE96827 (UnityPlayer) PlayerRender
    30. 0x00007FFA1CE884F7 (UnityPlayer) ExecutePlayerLoop
    31. 0x00007FFA1CE88599 (UnityPlayer) ExecutePlayerLoop
    32. 0x00007FFA1CE8A592 (UnityPlayer) PlayerLoop
    33. 0x00007FFA1CC52D55 (UnityPlayer) PerformMainLoop
    34. 0x00007FFA1CC517CA (UnityPlayer) MainMessageLoop
    35. 0x00007FFA1CC55801 (UnityPlayer) UnityMainImpl
    36. 0x00007FFA1CC5914B (UnityPlayer) UnityMain
    37. 0x00007FF652B911F2 (Lightmatter) __scrt_common_main_seh
    38. 0x00007FFAB2267BD4 (KERNEL32) BaseThreadInitThunk
    39. 0x00007FFAB2E4CED1 (ntdll) RtlUserThreadStart
    We are using 2048x2048 light cookies on our lamps.
    We are using a combination of Async level loading to seamlessly load between scenes when playing in sequence. However, players can also jump directly to a scene via a menu. In this case, we manually load a scene (see code below).

    Code (CSharp):
    1. public void InitiateManualSceneLoading(int index)
    2.     {
    3.         // This is used to load a specific scene instead of having to go through the whole sequence
    4.         // -1 loads title screen
    5.  
    6.         CurrentlyLoadingManualScene = true;
    7.         //CustomDebug.Log($"CurrentlyLoadingManualScene: {CurrentlyLoadingManualScene}", DebugType.SceneLoading, gameObject);
    8.  
    9.         StartCoroutine(LoadSceneManuallyWhenReady(index));
    10.     }
    11.  
    12.     public static bool CurrentlyFading()
    13.     {
    14.         if (Player_Manager.Instance == null ||
    15.             Player_Manager.Instance.Common.MenuManager.ScreenFade == null)
    16.             return false;
    17.         else
    18.             return Player_Manager.Instance.Common.MenuManager.ScreenFade.CurrentlyFading;
    19.     }
    20.  
    21.     private IEnumerator LoadSceneManuallyWhenReady(int index)
    22.     {
    23.         // NOTE:
    24.         // Using LoadScene() seems to destroy the async scenes in memory.
    25.         // When loading scene directly (non-async), scenes that are stored in memory (90%) are briefely activated (Awake() and OnEnable() are called, but NOT Start()),
    26.         // before the target scene is loaded.
    27.         // Unsure if this can create problems with memory management -G 16/11/2018
    28.  
    29.         CurrentlyLoadingManualScene = true;
    30.         //CustomDebug.Log($"CurrentlyLoadingManualScene: {CurrentlyLoadingManualScene}", DebugType.SceneLoading, gameObject);
    31.  
    32.         Player_Manager.Instance.SetState(typeof(Player_State_Useless));
    33.         StaticHelperClass.SetDontDestroyOnLoad(Player_Manager.Instance.Common.PlayerGameObject); // make sure the player isn't destroyed
    34.  
    35.         float waitDelay = 2f; // not sure if this has any benefits for the loading performance -G, 10/4/2018
    36.  
    37.         //CustomDebug.Log("LoadSceneManuallyWhenReady: " + index, DebugType.SceneLoading);
    38.  
    39.         // Wait until the asynchronous scene fully loads
    40.         while (SceneLoader.AsyncLoadOperation != null && !SceneLoader.SceneLoaded90Percent)
    41.         {
    42.             //CustomDebug.Log($"Waiting for scene {SceneLoader.SceneToLoad}", DebugType.SceneLoading);
    43.             yield return new WaitForSeconds(waitDelay);
    44.         }
    45.  
    46.         while (CurrentlyFading())
    47.         {
    48.             //CustomDebug.Log("Waiting for fading to finish (LoadSceneManuallyWhenReady)", DebugType.SceneLoading, this);
    49.             yield return null;
    50.         }
    51.  
    52.         NextLevelIndex = index;
    53.         if (NextLevelIndex < 0)
    54.             NextLevelIndex = 0;
    55.  
    56.         CurrentLevelIndex = NextLevelIndex;
    57.  
    58.  
    59.         #region Unload all scenes in memory
    60.         AsyncOperation asyncUnload = null;
    61.  
    62.         // SCENES CURRENTLY ACTIVE
    63.         for (int i = 0; i < _scenesActivated.Count; i++)
    64.         {
    65.             if (_scenesActivated[i] != null)
    66.             {
    67.                 //CustomDebug.Log($"Async unload of scene {_scenesActivated[i]}", DebugType.SceneLoading);
    68.                 asyncUnload = SceneManager.UnloadSceneAsync(_scenesActivated[i]);
    69.                 yield return asyncUnload;
    70.             }
    71.         }
    72.  
    73.         // SCENES LOADED INTO MEMORY
    74.         for (int i = 0; i < _scenesLoadedInMemory.Count; i++)
    75.         {
    76.             if (_scenesLoadedInMemory[i] != null)
    77.             {
    78.                 //CustomDebug.Log($"Async unload of scene {_scenesLoadedInMemory[i]}", DebugType.SceneLoading);
    79.                 asyncUnload = SceneManager.UnloadSceneAsync(_scenesLoadedInMemory[i]);
    80.                 yield return asyncUnload;
    81.             }
    82.         }
    83.  
    84.         // CURRENT ACTIVE SCENE
    85.         //CustomDebug.Log($"Async unload of scene {SceneManager.GetActiveScene().name}", DebugType.SceneLoading);
    86.         asyncUnload = SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene());
    87.         yield return asyncUnload;
    88.  
    89.         Resources.UnloadUnusedAssets(); // also automatically calls GC.Collect()
    90.         Caching.ClearCache();
    91.         #endregion
    92.  
    93.         SceneManager.CreateScene("temp"); // https://forum.unity.com/threads/scenemanager-unloadsceneasync-returns-null.472764/
    94.  
    95.  
    96.         yield return new WaitForSeconds(1); // just to be sure things are unloaded before we continue
    97.         SceneLoader.CancelAsyncOperation();
    98.  
    99.         string sceneToLoad;
    100.  
    101.         if (index == BuildManager.TITLE_SCREEN_INDEX)
    102.             sceneToLoad = BuildManager.TITLE_SCREEN;
    103.         else if (index == BuildManager.END_CREDITS_INDEX)
    104.             sceneToLoad = BuildManager.END_CREDITS;
    105.         else
    106.             sceneToLoad = CurrentReadOnlyScenes[index];
    107.  
    108.         SceneManager.sceneLoaded += SceneHasBeenManuallyLoadedWithoutAsync;
    109.  
    110.         SavePlayerProgress();
    111.         Player_Manager.Instance.Common.ResetAllPlayerSettings(true, true);
    112.  
    113.         SceneManager.LoadScene(sceneToLoad);
    114.     }
    Bug report: 1209763
     

    Attached Files:

  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    7,793
    Thanks, we're take a look.
     
unityunity