Search Issue Tracker
Won't Fix
Votes
0
Found in
2021.2
2021.2.9f1
2022.1
2022.2
Issue ID
1410334
Regression
No
Editor crashes with no stack trace when loading a new scene in Awake() function
Reproduction steps:
1. Open users attached project
2. Open /_DreamIsland/_Scenes/Title
3. Enter and Exit the Play Mode twice
Expected result: A new scene is loaded
Actual result: Editor crashes
Reproducible with: 2021.2.17f1, 2022.1.0b13, 2022.2.0a8
Could not test with: 2019.4.37f1, 2020.3.31f1 (could not downgrade the project)
Note: sometimes it might take multiple tries for Editor to crash
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- UI Toolkit throws warning and fails to clear references when fields are not typed as UnityEngine.Object
- "Shader warning in 'Hidden/Light2D': implicit truncation of vector type" is thrown when building Universal 2D template
- AI Assistant breaks compilation of packages using System.Runtime.CompilerServices.Unsafe via auto-referencing
- Unity Hub checks the "Documentation" module by default on the 6.4 and 6.5 streams despite that it was unchecked with the previous installs
- Shortcut that toggles between Dopesheet and Curves Views in the Animation Window's Timeline is mislabed
Resolution Note:
The crash happens in cri_ware_unity.dll!00007ffe85bc55f0() which seems to be a native plugin made by https://www.criware.com/en/
From my investigation this happens in:
```
private void SceneLoaded(Scene nextScene, LoadSceneMode mode)
{
if (nextScene.name==$"{SceneStateEnum.Title}")
{
bgmManager.PlayAndStopBgm(BgmEnum.TitleBGM, false);
}else if(nextScene.name==$"{SceneStateEnum.Tutorial}")
{
bgmManager.PlayAndStopBgm(BgmEnum.TutorialBGM, true);
}
}
```
because `bgmManager` is null and it calls into native code without any check.
By reading the code I see it adds a `sceneLoaded` callback, but it doesn't remove it.
```
private void Awake()
{
SceneManager.sceneLoaded += SceneLoaded;
}
```
This callback will remain registered and `SceneLoaded` will be called every time a new scene is loaded. Adding
```
private void OnDestroy()
{
SceneManager.sceneLoaded -= SceneLoaded;
}
```
solves the issue, but I think a bug report should be filed to the native plugin maintainers to make sure they handle calls on null pointers