Search Unity

2019.4.0 shader local keywords causing hard crash on macOS

Discussion in 'Editor & General Support' started by greg-harding, Jul 8, 2020.

  1. greg-harding

    greg-harding

    Joined:
    Apr 11, 2013
    Posts:
    524
    hey everyone,

    we are experiencing a hard crash on macOS builds that is related to shader compiling either in prewarmed shader asset or at runtime when a scene is loaded. Other platforms aren't affected - iOS, tvOS and the editor are all fine. Only macOS standalone builds are crashing. Mono and IL2CPP builds both crash.

    After a lot of messing around it seems like shader #pragmas for local keywords are to blame, and the issue was introduced moving from Unity 2019.3.15 to 2019.4.0.

    We filed a bug report with repro project a few weeks ago that shows the problem and little hacks to try to work around it - Case #1258697


    Update:
    Unity repro'd the bug and have sent it to the fixit factory. It also affects Unity 2019.3.16, 2019.4.0-2, 2020.1, 2020.2 and Windows desktop apps.
    https://issuetracker.unity3d.com/is...hen-custom-shader-with-local-keywords-is-used

    Update 2: Unity QA has replied saying they have fixed this bug. Ultimately the bug was caused when a shader used local keywords and had a fallback to a shader that also used local keywords.


    Reordering various '#pragma shader_feature_local' keyword definitions or adding redundant local keywords in some shaders seems to convince the runtime shader compiler not to crash but these hacks are only working in our smaller repro projects at the moment. We cannot use the same fixes on our main project and convince it to work - mac builds still crash.

    Has anyone else hit similar problems with shaders in 2019.4.x? If so, can you share any tips to workaround the problem?

    Update: We managed to fix some of our crash issues by changing fallback shaders away from the Unity standard shader, eg. using Fallback "Mobile/VertexLit".

    Thanks for any help or advice.


    Example crashlog of prewarming shaders showing the shaderlab crash in a Mono build;

    Code (csharp):
    1. Obtained 35 stack frames.
    2. #0  0x00000110bf7248 in ShaderLab::Pass::ApplyPass(unsigned int, ShaderPropertySheet const*, ShaderPassContext&, Shader*, int, int, ShaderLab::GrabPasses const*, ShaderLab::SubPrograms*, DeviceRenderStateBlock const*)
    3. #1  0x00000110bf1126 in DrawVBOChunkWithPass(Shader*, int, ShaderLab::Pass*, ShaderPassContext&, WarmupPassSetup const&, DynamicVBO*)
    4. #2  0x00000110bf0029 in ShaderVariantCollection::WarmupOneShaderImpl(Shader*, vector_set<ShaderVariantCollection::VariantInfo, std::__1::less<ShaderVariantCollection::VariantInfo>, std::__1::allocator<ShaderVariantCollection::VariantInfo> > const&, WarmupPassSetup const&, DynamicVBO*, void (*)(Shader*, int, ShaderLab::Pass*, ShaderKeywordSet const&, WarmupPassSetup const&, DynamicVBO*, void*, ShaderPassContext&), void*)
    5. #3  0x00000110bf0297 in ShaderVariantCollection::WarmupShadersImpl(void (*)(Shader*, int, ShaderLab::Pass*, ShaderKeywordSet const&, WarmupPassSetup const&, DynamicVBO*, void*, ShaderPassContext&), void*)
    6. #4  0x00000110bf014d in ShaderVariantCollection::WarmupShaders(bool)
    7. #5  0x00000110562745 in GraphicsSettings::WarmupPreloadedShaders()
    8. #6  0x00000110b15098 in InitializeEngineGraphics(bool)::playerLoadFirstScenePreAwakeRegistrator::Forward()
    9. #7  0x000001101d1b92 in CallbackArray::Invoke()
    10. #8  0x00000110b3b009 in PlayerLoadFirstScene(bool)
    11. #9  0x0000011162773d in ContinueSetupUnityPlayer(bool)
    12. #10 0x00000111620145 in -[PlayerAppDelegate continuePlayerSetup]
    13. #11 0x00000111620029 in -[PlayerAppDelegate applicationDidFinishLaunching:]
    14. #12 0x007fff396eb89f in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
    15. #13 0x007fff396eb833 in ___CFXRegistrationPost1_block_invoke
    16. #14 0x007fff396eb7a8 in _CFXRegistrationPost1
    17. #15 0x007fff396eb414 in ___CFXNotificationPost_block_invoke
    18. #16 0x007fff396bb58d in -[_CFXNotificationRegistrar find:object:observer:enumerator:]
    19. #17 0x007fff396baa39 in _CFXNotificationPost
    20. #18 0x007fff3bd35786 in -[NSNotificationCenter postNotificationName:object:userInfo:]
    21. #19 0x007fff36973ce3 in -[NSApplication _postDidFinishNotification]
    22. #20 0x007fff36973a22 in -[NSApplication _sendFinishLaunchingNotification]
    23. #21 0x007fff36970ae3 in -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:]
    24. #22 0x007fff36970728 in -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:]
    25. #23 0x007fff3bd60a26 in -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:]
    26. #24 0x007fff3bd60890 in _NSAppleEventManagerGenericHandler
    27. #25 0x007fff3aa67203 in _AppleEventsCheckInAppWithBlock
    28. #26 0x007fff3aa66929 in _AppleEventsCheckInAppWithBlock
    29. #27 0x007fff3aa5ebd7 in aeProcessAppleEvent
    30. #28 0x007fff383347fa in AEProcessAppleEvent
    31. #29 0x007fff3696aac1 in _DPSNextEvent
    32. #30 0x007fff36969070 in -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
    33. #31 0x007fff3695ad7e in -[NSApplication run]
    34. #32 0x007fff3692cb86 in NSApplicationMain
    35. #33 0x00000111628275 in PlayerMain(int, char const**)
    36. #34 0x007fff736f0cc9 in start
     
    Last edited: Jul 11, 2020