Crash in BatchRendererGroup::UnregisterMaterial

I have a crash in BatchRendererGroup::UnregisterMaterial every time the client world is disposed in my netcode entities project via world.DestroyAllSystemsAndLogException(out _).

Android stacktrace (relevant only):

Thread 0 (crashed)
0   libunity.so                        0x0000007209c3a520 BatchRendererGroup::UnregisterMaterial(BatchMaterialID)
1   libunity.so                        0x00000072095478bc BatchRendererGroup_CUSTOM_UnregisterMaterial_Injected(ScriptingBackendNativeObjectPtrOpaque*, BatchMaterialID const&)
2   libil2cpp.so                       0x0000000008564fa0 BatchRendererGroup_UnregisterMaterial_Injected_m9F737517B91D65A3F40AFDAD9F1AB70F0AE8C3C8 (D:/project/Library/Bee/artifacts/Android/il2cppOutput/cpp\UnityEngine.CoreModule__4.cpp:22151)
3   libil2cpp.so                       0x00000071ed0fffa8 BatchRendererGroup_UnregisterMaterial_m1A912834A8206072C163C5640C6A1448BC27CF24 (D:/project/Library/Bee/artifacts/Android/il2cppOutput/cpp\UnityEngine.CoreModule__4.cpp:21903)
4   libil2cpp.so                       0x00000071ec86ebf0 RegisterMaterialsAndMeshesSystem_UnregisterMaterialsMeshes_m96BDD648CF34533DF24183797EFFDDB9FAD0EECE (D:/project/Library/Bee/artifacts/Android/il2cppOutput/cpp\Unity.Entities.Graphics__1.cpp:14639)
5   libil2cpp.so                       0x00000071ec86ea9c RegisterMaterialsAndMeshesSystem_OnDestroy_m52056310417B7BC81BD05974177A10A30CE29D98 (D:/project/Library/Bee/artifacts/Android/il2cppOutput/cpp\Unity.Entities.Graphics__1.cpp:14542)
6   libil2cpp.so                       0x00000071ec9bede8 World_DestroyAllSystemsAndLogException_m5FC4B151A3F76F4ADF7EDA18EDECEC9E1B60F821

This occurs 100% in Android builds. I can very rarely reproduce it while playing in the editor, but not at the same point - instead, only while exiting play mode. This crashes the entire editor.

Editor.log with crash (relevant only):

0x00007FF681D22D49 (Unity) BatchRendererGroup::UnregisterMaterial
0x00007FF681504405 (Unity) BatchRendererGroup_CUSTOM_UnregisterMaterial_Injected
0x000001F71AFF3714 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Rendering.BatchRendererGroup:UnregisterMaterial_Injected (UnityEngine.Rendering.BatchRendererGroup,UnityEngine.Rendering.BatchMaterialID&)
0x000001F71AFF355B (Mono JIT Code) UnityEngine.Rendering.BatchRendererGroup:UnregisterMaterial (UnityEngine.Rendering.BatchMaterialID)
0x000001F71AFF3493 (Mono JIT Code) [.\Library\PackageCache\com.unity.entities.graphics@1.2.0\Unity.Entities.Graphics\EntitiesGraphicsSystem.cs:2605] Unity.Rendering.EntitiesGraphicsSystem:UnregisterMaterial (UnityEngine.Rendering.BatchMaterialID)
0x000001F71AFF2B9B (Mono JIT Code) [.\Library\PackageCache\com.unity.entities.graphics@1.2.0\Unity.Entities.Graphics\EntitiesGraphicsSystem.cs:411] Unity.Rendering.RegisterMaterialsAndMeshesSystem:UnregisterMaterialsMeshes (Unity.Rendering.BRGRenderMeshArray&)
0x000001F70044689B (Mono JIT Code) [.\Library\PackageCache\com.unity.entities.graphics@1.2.0\Unity.Entities.Graphics\EntitiesGraphicsSystem.cs:399] Unity.Rendering.RegisterMaterialsAndMeshesSystem:OnDestroy ()
0x000001F6FF4E2D50 (Mono JIT Code) [.\Packages\com.unity.entities.1.2.0\Unity.Entities\ComponentSystemBase.cs:305] Unity.Entities.ComponentSystemBase:OnDestroy_Internal ()
0x000001F6FF4E1573 (Mono JIT Code) [.\Packages\com.unity.entities.1.2.0\Unity.Entities\World.cs:1141] Unity.Entities.World:smile:estroyAllSystemsAndLogException (bool&)
0x000001F7003EFCCB (Mono JIT Code) [.\Packages\com.unity.entities.1.2.0\Unity.Entities\World.cs:306] Unity.Entities.World:smile:ispose ()
0x000001F7003EEF93 (Mono JIT Code) [.\Packages\com.unity.entities.1.2.0\Unity.Entities\World.cs:332] Unity.Entities.World:smile:isposeAllWorlds ()
0x000001F6FD5F2FB3 (Mono JIT Code) [.\Packages\com.unity.entities.1.2.0\Unity.Entities\DefaultWorldInitialization.cs:92] Unity.Entities.DefaultWorldInitialization:smile:omainUnloadOrPlayModeChangeShutdown ()
0x000001F7003EDE73 (Mono JIT Code) [.\Packages\com.unity.entities.1.2.0\Unity.Entities\DefaultWorldInitializationProxy.cs:28] Unity.Entities.DefaultWorldInitializationProxy:OnDisable ()
0x000001F6EC240188 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007FFB5D274BFE (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\mini\mini-runtime.c:3445] mono_jit_runtime_invoke
0x00007FFB5D1AD254 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:3068] do_runtime_invoke
0x00007FFB5D1AD3CC (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:3115] mono_runtime_invoke

Unity 2022.3.21f1.
DOTS: 1.2.0 (release).

I am also investigating this, too. Do you load/unload scenes in async?

Also found this. Says it’s fixed on 2022.3.23f1.

Yup, I can confirm that it’s fixed in 2022.3.23. All good :slight_smile:

1 Like

Not fixed in 2023 unity tho :stuck_out_tongue:

I apologize for the necro. But, this is still occurring in Unity 6000.0.15f1

That’s preview version which is not maintained anymore, you should update to release version first - 6000.0.23f1 and above

1 Like