My game always crashes when building a standalone release, it fails at "OnPreprocessShaderVariants"

I’m not sure where to go from here. The game runs fine in the editor, but when I try to build a standalone executable (for win64) it builds for about an hour, then dies at some point when it’s stripping shader variants. I’ve tried NOT stripping anything, but it still dies at the same place. The top of the crashing stacktrace is always “OnPreprocessShaderVariants”. Does anyone have any ideas what else I can try?


Here’s the actual stacktrace:

Obtained 67 stack frames
0x00007ff788a4f2d8 (Unity) OnPreprocessShaderVariants
0x00007ff7889b8818 (Unity) CompileGpuProgramSnippets
0x00007ff7889ba01f (Unity) CompileShaderSubprograms
0x00007ff7889b9721 (Unity) CompileShaderSubprograms
0x00007ff78944366b (Unity) Shader::Transfer<StreamedBinaryWrite>
0x00007ff787dee65b (Unity) SerializedFile::WriteObject
0x00007ff787dd8158 (Unity) PersistentManager::WriteFile
0x00007ff787dd9f3f (Unity) PersistentManager::WriteFile
0x00007ff788a7b729 (Unity) WriteSharedAssetFile
0x00007ff788a6897e (Unity) CompileSharedAssetsFile
0x00007ff7897554eb (Unity) BuildPlayerData
0x00007ff78975e58c (Unity) DoBuildPlayer_Build
0x00007ff78975cf46 (Unity) DoBuildPlayer
0x00007ff789750f8d (Unity) BuildPlayer
0x00007ff787635b4d (Unity) BuildPipeline::BuildPlayerInternalNoCheck
0x00007ff78748ca5f (Unity) BuildPipeline_CUSTOM_BuildPlayerInternalNoCheck
0x000001a4bd876be7 (Mono JIT Code) (wrapper managed-to-native) UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck (string[],string,string,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,int,UnityEditor.BuildOptions,string[],bool)
0x000001a4bd8762d3 (Mono JIT Code) UnityEditor.BuildPlayerWindow/DefaultBuildMethods:BuildPlayer (UnityEditor.BuildPlayerOptions)
0x000001a4bd870653 (Mono JIT Code) UnityEditor.BuildPlayerWindow:CallBuildMethods (bool,UnityEditor.BuildOptions)
0x000001a4bd890ef3 (Mono JIT Code) UnityEditor.BuildPlayerWindow:GUIBuildButtons (UnityEditor.Modules.IBuildWindowExtension,bool,bool,bool,UnityEditor.Build.BuildPlatform,UnityEditor.Modules.IBuildPostprocessor)
0x000001a4bd8875b3 (Mono JIT Code) UnityEditor.BuildPlayerWindow:ShowBuildTargetSettings ()
0x000001a4b9319583 (Mono JIT Code) UnityEditor.BuildPlayerWindow:OnGUI ()
0x000001a4a82d834a (Mono JIT Code) UnityEditor.HostView:InvokeOnGUI (UnityEngine.Rect)
0x000001a4a82d8163 (Mono JIT Code) UnityEditor.DockArea:DrawView (UnityEngine.Rect)
0x000001a4a82ca65b (Mono JIT Code) UnityEditor.DockArea:OldOnGUI ()
0x000001a19ca01d2f (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:DoOnGUI (UnityEngine.Event,UnityEngine.Matrix4x4,UnityEngine.Rect,bool,UnityEngine.Rect,System.Action,bool)
0x000001a19ca00f5b (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,UnityEngine.Matrix4x4,UnityEngine.Rect,System.Action,bool)
0x000001a4b930793b (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,System.Action,bool)
0x000001a4b93077a3 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,bool)
0x000001a4b930732b (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUIRaw (UnityEngine.UIElements.EventBase,bool,bool)
0x000001a4b9307213 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:SendEventToIMGUI (UnityEngine.UIElements.EventBase,bool,bool)
0x000001a45f4048cb (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleEvent (UnityEngine.UIElements.EventBase)
0x000001a45f3ee318 (Mono JIT Code) UnityEngine.UIElements.CallbackEventHandler:HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase)
0x000001a4b9305423 (Mono JIT Code) UnityEngine.UIElements.MouseCaptureDispatchingStrategy:DispatchEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
0x000001a45f3ec52e (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel,bool)
0x000001a45f3ec02b (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ProcessEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
0x000001a45f3f13bb (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ProcessEventQueue ()
0x000001a45f3dfc93 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:OpenGate ()
0x000001a45f3eff4b (Mono JIT Code) UnityEngine.UIElements.EventDispatcherGate:Dispose ()
0x000001a45f3ec2b3 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:ProcessEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel)
0x000001a45f3eba03 (Mono JIT Code) UnityEngine.UIElements.EventDispatcher:Dispatch (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.IPanel,UnityEngine.UIElements.DispatchMode)
0x000001a45f3eb87b (Mono JIT Code) UnityEngine.UIElements.BaseVisualElementPanel:SendEvent (UnityEngine.UIElements.EventBase,UnityEngine.UIElements.DispatchMode)
0x000001a47f501e3b (Mono JIT Code) UnityEngine.UIElements.UIElementsUtility:DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel)
0x000001a47f5018e3 (Mono JIT Code) UnityEngine.UIElements.UIElementsUtility:UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (int,intptr,bool&)
0x000001a47f50169f (Mono JIT Code) UnityEngine.UIElements.UIEventRegistration:ProcessEvent (int,intptr)
0x000001a47f5015bb (Mono JIT Code) UnityEngine.UIElements.UIEventRegistration/<>c:<.cctor>b__1_2 (int,intptr)
0x000001a47f50140d (Mono JIT Code) UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
0x000001a47f5014c6 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_int_intptr_intptr& (object,intptr,intptr,intptr)
0x00007ff82a94e034 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke 
0x00007ff82a88e724 (mono-2.0-bdwgc) [object.c:3064] do_runtime_invoke 
0x00007ff82a88e8bc (mono-2.0-bdwgc) [object.c:3111] mono_runtime_invoke 
0x00007ff787d44474 (Unity) scripting_method_invoke
0x00007ff787d3f094 (Unity) ScriptingInvocation::Invoke
0x00007ff787d389d5 (Unity) ScriptingInvocation::Invoke<void>
0x00007ff787e6409a (Unity) Scripting::UnityEngine::GUIUtilityProxy::ProcessEvent
0x00007ff78886a716 (Unity) GUIView::ProcessRetainedMode
0x00007ff788d9fefb (Unity) GUIView::OnInputEvent
0x00007ff78886a527 (Unity) GUIView::ProcessInputEvent
0x00007ff788da0e17 (Unity) GUIView::ProcessEventMessages
0x00007ff788d9a9c3 (Unity) GUIView::GUIViewWndProc
0x00007ff8d1a01c4c (USER32) CallWindowProcW
0x00007ff8d1a00ea6 (USER32) DispatchMessageW
0x00007ff788d76143 (Unity) MainMessageLoop
0x00007ff788d7aadb (Unity) WinMain
0x00007ff78a08aaa2 (Unity) __scrt_common_main_seh
0x00007ff8d1bb54e0 (KERNEL32) BaseThreadInitThunk
0x00007ff8d2a0485b (ntdll) RtlUserThreadStart

I’ve got the same problem, I tried removing assets added since last successful build, but no luck. It built in 2021.2.3, but not in 2021.2.5 nor 2021.2.8

Compiling shader "Universal Render Pipeline/Lit" pass "ForwardLit" (fp)
  [5.35s] 100M / ~641M prepared
  [12.71s] 200M / ~641M prepared
  [20.40s] 300M / ~641M prepared
  [26.18s] 400M / ~641M prepared
  [36.23s] 500M / ~641M prepared
  [41.87s] 600M / ~641M prepared
    100270080 variants, prepared in 44.01 seconds, starting stripping...

=================================================================
	Native Crash Reporting
=================================================================
Got a UNKNOWN while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
	Managed Stacktrace:
=================================================================
	  at <unknown> <0xffffffff>
	  at UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck <0x001a7>
	  at DefaultBuildMethods:BuildPlayer <0x013aa>
	  at UnityEditor.BuildPlayerWindow:CallBuildMethods <0x0098a>
	  at <>c__DisplayClass43_0:<GUIBuildButtons>b__0 <0x0008a>
	  at UnityEditor.GenericMenu:CatchMenu <0x001f9>
	  at <Module>:runtime_invoke_void__this___object_object_int <0x001b6>
=================================================================
Received signal SIGSEGV
Obtained 40 stack frames
0x00007ff66d6a0df8 (Unity) OnPreprocessShaderVariants
0x00007ff66d60a2c1 (Unity) CompileGpuProgramSnippets
0x00007ff66d60baff (Unity) CompileShaderSubprograms
0x00007ff66d60b201 (Unity) CompileShaderSubprograms
0x00007ff66e09596b (Unity) Shader::Transfer
0x00007ff66ca3f02b (Unity) SerializedFile::WriteObject
0x00007ff66ca28b28 (Unity) PersistentManager::WriteFile
0x00007ff66ca2a90f (Unity) PersistentManager::WriteFile
0x00007ff66d6cd259 (Unity) WriteSharedAssetFile
0x00007ff66d6ba4ae (Unity) CompileSharedAssetsFile
0x00007ff66e3a7cfb (Unity) BuildPlayerData
0x00007ff66e3b0d9c (Unity) DoBuildPlayer_Build
0x00007ff66e3af756 (Unity) DoBuildPlayer
0x00007ff66e3a379d (Unity) BuildPlayer
0x00007ff66c285fdd (Unity) BuildPipeline::BuildPlayerInternalNoCheck
0x00007ff66c0e4f5f (Unity) BuildPipeline_CUSTOM_BuildPlayerInternalNoCheck
0x000001db891392b8 (Mono JIT Code) (wrapper managed-to-native) UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck (string[],string,string,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,int,UnityEditor.BuildOptions,string[],bool)
0x000001db89137bbb (Mono JIT Code) UnityEditor.BuildPlayerWindow/DefaultBuildMethods:BuildPlayer (UnityEditor.BuildPlayerOptions)
0x000001db896697bb (Mono JIT Code) UnityEditor.BuildPlayerWindow:CallBuildMethods (bool,UnityEditor.BuildOptions)
0x000001db89668dcb (Mono JIT Code) UnityEditor.BuildPlayerWindow/<>c__DisplayClass43_0:b__0 ()
0x000001db89668cba (Mono JIT Code) UnityEditor.GenericMenu:CatchMenu (object,string[],int)
0x000001db89668847 (Mono JIT Code) (wrapper runtime-invoke) :runtime_invoke_void__this___object_object_int (object,intptr,intptr,intptr)
0x00007ff834d6e034 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke 
0x00007ff834cae724 (mono-2.0-bdwgc) [object.c:3064] do_runtime_invoke 
0x00007ff834cae8bc (mono-2.0-bdwgc) [object.c:3111] mono_runtime_invoke 
0x00007ff66c994e44 (Unity) scripting_method_invoke
0x00007ff66c98fa64 (Unity) ScriptingInvocation::Invoke
0x00007ff66d3fa1b2 (Unity) CustomPopupMenuInterface::Execute
0x00007ff66d3c46a0 (Unity) MenuController::ExecuteMenuItem
0x00007ff66d9e17e2 (Unity) ShowDelayedContextMenu
0x00007ff66d9f1c46 (Unity) GUIView::OnInputEvent
0x00007ff66d4bbd07 (Unity) GUIView::ProcessInputEvent
0x00007ff66d9eaabe (Unity) GUIView::DoPaint
0x00007ff66d46e7df (Unity) TooltipManager::Update
0x00007ff66d58c2e2 (Unity) Application::TickTimer
0x00007ff66d9c803a (Unity) MainMessageLoop
0x00007ff66d9cc90b (Unity) WinMain
0x00007ff66ecdd942 (Unity) __scrt_common_main_seh
0x00007ff88b017034 (KERNEL32) BaseThreadInitThunk
0x00007ff88b562651 (ntdll) RtlUserThreadStart

FYI this is fixed in the latest 2022.1.0b7 beta version of the editor.