[2021.2.14f1] Unhandled exception UnityPlayer.dll 0xC0000005 Access violation writing location

Hello,

I’m encountering a crash in my UWP app while running in Debug mode. The crash occurs when I attempt to unload a scene after quitting a level, resulting in the following error:

Unhandled exception at 0x00007FF80A2EB02B (UnityPlayer.dll) in Winmed.exe: 0xC0000005: Access violation writing location 0x000002E38200000C.

What’s puzzling is that this error points to a “write” access violation, even though I’m merely unloading a scene.

Here’s the call stack from Visual Studio:

UnityPlayer.dll!LightmapSettings::RemoveLightmaps(int)
UnityPlayer.dll!DidUnloadScene(int)
UnityPlayer.dll!RuntimeSceneManager::UnloadAllScenesWithoutDestroyingGameObjects(void (*)(class UnityScene &))
UnityPlayer.dll!UnloadGameScene(void)
UnityPlayer.dll!LoadSceneOperation::PlayerLoadSceneFromThread(void)
UnityPlayer.dll!LoadSceneOperation::IntegrateMainThread(void)
UnityPlayer.dll!PreloadManager::UpdatePreloadingSingleStep(enum PreloadManager::UpdatePreloadingFlags, int)
UnityPlayer.dll!PreloadManager::WaitForAllAsyncOperationsToComplete(void)
UnityPlayer.dll!PreloadManager::UpdatePreloading(void)
UnityPlayer.dll!ExecutePlayerLoop(struct NativePlayerLoopSystem *)
UnityPlayer.dll!ExecutePlayerLoop(struct NativePlayerLoopSystem *)
UnityPlayer.dll!PlayerLoop(void)
UnityPlayer.dll!metro::MainLoop(bool)

I came across a post suggesting that access violations like this could be due to missing references, potentially resulting from null reference exceptions. However, I have checked, and there don’t seem to be any null lightmaps in my scene.

Any insights into why this might be happening, or steps to resolve this issue, would be greatly appreciated.

Thank you!

Fixed! This issue is a known bug that occurs in Unity versions prior to 2020.3.17f1.

If you can’t update Unity, you can work around this issue by adding the following lines before loading a new scene:

 // Clear lightmaps (necessary for UWP builds)
LightmapSettings.lightmaps = new LightmapData[0];
Resources.UnloadUnusedAssets();