Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Crash standalone build calling 'FindObjectsOfType' during Awake.

Discussion in 'Scripting' started by lordofduct, Oct 31, 2018.

  1. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,513
    I'm wondering if anyone else has witnessed when building for Windows standalone, if the game crashes if you call FindObjectsOfType during Awake in some scenes.

    It only happens occassionally, and only on certain hardware, for me. My main rig never has it happen, but I have customers who have it happen regularly, my QA guy sometimes has it happen, and tonight I finally was able to reproduce on an old 1st generation i7 rig I pulled out of the closet.

    The log file always shows a call to FindObjectsOfType in the callstack when it occurs.

    Example of the log:

    Code (csharp):
    1.  
    2. ========== OUTPUTTING STACK TRACE ==================
    3.  
    4.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB40186CC0)
    5. 0x00007FFB40186CC0 (UnityPlayer) (function-name not available)
    6.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB4048A25E)
    7. 0x00007FFB4048A25E (UnityPlayer) (function-name not available)
    8.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB4066CAB7)
    9. 0x00007FFB4066CAB7 (UnityPlayer) (function-name not available)
    10. 0x0000014F3DB5A4BC (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Object:FindObjectsOfType (System.Type)
    11. 0x0000014F3DB5A30B (Mono JIT Code) Pathfinding.RelevantGraphSurface:FindAllGraphSurfaces ()
    12. 0x0000014F3DB5A076 (Mono JIT Code) AstarPath:Awake ()
    13. 0x0000014F2FA51DEB (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    14. 0x00007FFB5A17671B (mono) mono_set_defaults
    15. 0x00007FFB5A0C8A71 (mono) mono_runtime_invoke
    16.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB404914A4)
    17. 0x00007FFB404914A4 (UnityPlayer) (function-name not available)
    18.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB4048E9B0)
    19. 0x00007FFB4048E9B0 (UnityPlayer) (function-name not available)
    20.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB4048EA6E)
    21. 0x00007FFB4048EA6E (UnityPlayer) (function-name not available)
    22.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB404731D6)
    23. 0x00007FFB404731D6 (UnityPlayer) (function-name not available)
    24.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB40472FEE)
    25. 0x00007FFB40472FEE (UnityPlayer) (function-name not available)
    26.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB40472B06)
    27. 0x00007FFB40472B06 (UnityPlayer) (function-name not available)
    28.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB40472D20)
    29. 0x00007FFB40472D20 (UnityPlayer) (function-name not available)
    30.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB404BA5B7)
    31. 0x00007FFB404BA5B7 (UnityPlayer) (function-name not available)
    32.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB403944EF)
    33. 0x00007FFB403944EF (UnityPlayer) (function-name not available)
    34.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB40395E59)
    35. 0x00007FFB40395E59 (UnityPlayer) (function-name not available)
    36.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB40394B5B)
    37. 0x00007FFB40394B5B (UnityPlayer) (function-name not available)
    38.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB40396D63)
    39. 0x00007FFB40396D63 (UnityPlayer) (function-name not available)
    40.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB40396B4D)
    41. 0x00007FFB40396B4D (UnityPlayer) (function-name not available)
    42.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB4037A687)
    43. 0x00007FFB4037A687 (UnityPlayer) (function-name not available)
    44.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB4037A712)
    45. 0x00007FFB4037A712 (UnityPlayer) (function-name not available)
    46.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB4037C60F)
    47. 0x00007FFB4037C60F (UnityPlayer) (function-name not available)
    48.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB40A37165)
    49. 0x00007FFB40A37165 (UnityPlayer) (function-name not available)
    50.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB40A362AA)
    51. 0x00007FFB40A362AA (UnityPlayer) (function-name not available)
    52.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFB40A38A5B)
    53. 0x00007FFB40A38A5B (UnityPlayer) (function-name not available)
    54. 0x00007FFB40A38C2B (UnityPlayer) UnityMain
    55.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF789E91207)
    56. 0x00007FF789E91207 (gardenvariety) (function-name not available)
    57. 0x00007FFB85FC3034 (KERNEL32) BaseThreadInitThunk
    58. 0x00007FFB86111461 (ntdll) RtlUserThreadStart
    59.  
    60. ========== END OF STACKTRACE ===========
    61.  
    In this specific log it's AronGranberg's A* Pathfinding library.

    But it's not always that. I've had it happen on my own code which accessed FindObjectsOfType.

    What I've done is basically purged ALL usage of this function from my projects. And I'm attempting to purge it from Aron Granberg's project as well.

    BUT, that's ridiculous... I don't udnerstand why this would be happening in the first place.

    Biggest issue is that it's so unpredictable to reproduce. It's only on some hardware, and I can't determine when exactly it occurs. I can sort of predictably recreate it in my current game by going to this specific area and entering/exiting a door multiple times (which loads between 2 scenes) and after a few times it finally crashes.

    As a result it's hard to put together a bug report to send to Unity, and it NEVER happens in editor.

    ...

    So just wondering if anyone else has witnessed this.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,519
    I have not but if you are doing this on the VERY first frame of the game running, that might be part of the problem.

    Variously through the ages, Unity has had bugs during the first frame of the game. For a while on Android if you queried Screen in Awake() on the first frame of the game, it always returned 640x480. It was corrected by the time Start() ran, and it was correct in all subsequent frames of the game, so this could be something related.

    I always have a single-script scene in every Unity project I make called 'zeroscene' and it just launches the next scene, and therefore anything "interesting" I do is always on the second or later frame of the engine.
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    In addition to likely fixing your issue, it'd be good practice to put such a function in Start() rather than Awake().

    A good rule of thumb is: Awake() should handle things on this GameObject (or even this script) only. Start() handles things that rely on other GameObjects. FindObjectsOfType naturally falls into the latter category.
     
    Bunny83 likes this.
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,513
    So it's not on the very first frame of the game.

    It's only Awake of a scene loading, and well into the game. It happens when transitioning between scenes. This is part of why reproducing it is so difficult. It's well into the game, and doesn't occur predictably or even on the same hardware.

    Furthermore... as I said:
    I've stopped using FindObjectsOfType anywhere in my project. But unfortunately I also use a 3rd party program, Aron Granberg's A*, and it uses FindObjectsOfType. And I can't as easily remove it from there, or put it in Start.

    I have removed a few of the offending that were easy to purge as unnecessary for my use case from Aron Granber. But that was it.

    As you can see here:
    Code (csharp):
    1.  
    2.     protected override void Awake () {
    3.         base.Awake();
    4.         // Very important to set this. Ensures the singleton pattern holds
    5.         active = this;
    6.  
    7.         //LOD NOTE - removed this because we get weird crashes...
    8. #if UNITY_EDITOR
    9.         if (FindObjectsOfType(typeof(AstarPath)).Length > 1) {
    10.             Debug.LogError("You should NOT have more than one AstarPath component in the scene at any time.\n" +
    11.                 "This can cause serious errors since the AstarPath component builds around a singleton pattern.");
    12.         }
    13. #endif
    14.  
    15.         // Disable GUILayout to gain some performance, it is not used in the OnGUI call
    16.         useGUILayout = false;
    17.  
    18.         // This class uses the [ExecuteInEditMode] attribute
    19.         // So Awake is called even when not playing
    20.         // Don't do anything when not in play mode
    21.         if (!Application.isPlaying) return;
    22.  
    23.         if (OnAwakeSettings != null) {
    24.             OnAwakeSettings();
    25.         }
    26.  
    27.         // To make sure all graph modifiers have been enabled before scan (to avoid script execution order issues)
    28.         // LOD NOTE - removed this because we get weird crashes because it calls FindObjectsOfType... we don't use modifiers or surfaces, so it's not an issue
    29.         //GraphModifier.FindAllModifiers();
    30.         //RelevantGraphSurface.FindAllGraphSurfaces();
    31.  
    Note that Aron Granberg specifically calls it in Awake for ordering purposes


    I effectively am avoiding the bug for now. But, it's unfortunate that the bug exists. And I'm trying to see if anyone has evidence of it as well to help me try to build a reproducable bug report for Unity.


    I do as well, I call it boot scene.
     
    Last edited: Oct 31, 2018
  5. Babybus_Study

    Babybus_Study

    Joined:
    Oct 31, 2016
    Posts:
    14
    upload_2020-5-21_17-8-11.png




    I also encountered this crash. My Verision is 2017.4.36.
    This should be an exception of unity. Can someone solve it
     
  6. Reneguard

    Reneguard

    Joined:
    Mar 9, 2021
    Posts:
    1
    I am getting this error as well. Version 2019.4.29f1 (0eeae20b1d82)
    Code (CSharp):
    1. ========== OUTPUTTING STACK TRACE ==================
    2.  
    3. 0x00007FFDD8E83DB0 (UnityPlayer) UnityMain
    4. 0x00007FFDD91B155C (UnityPlayer) UnityMain
    5. 0x00007FFDD9246344 (UnityPlayer) UnityMain
    6. 0x000001C9ED8241BA (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Object:FindObjectsOfType (System.Type)
    7. 0x000001C9ED824083 (Mono JIT Code) UnityEngine.Object:FindObjectsOfType<T_REF> ()
    8. 0x000001CB5A55058B (Mono JIT Code) SRML.Console.ConsoleWindow:ToggleWindow ()
    9. 0x000001CB4785C6B3 (Mono JIT Code) SRML.Console.ConsoleWindow:OnGUI ()
    10. 0x000001CACDB84AF0 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    11. 0x00007FFDDDA0E270 (mono-2.0-bdwgc) mono_get_runtime_build_info
    12. 0x00007FFDDD992AE2 (mono-2.0-bdwgc) mono_perfcounters_init
    13. 0x00007FFDDD99BB3F (mono-2.0-bdwgc) mono_runtime_invoke
    14. 0x00007FFDD91B513D (UnityPlayer) UnityMain
    15. 0x00007FFDD91B2513 (UnityPlayer) UnityMain
    16.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFDD8BCEA24)
    17. 0x00007FFDD8BCEA24 (UnityPlayer) (function-name not available)
    18.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFDD8BCFB30)
    19. 0x00007FFDD8BCFB30 (UnityPlayer) (function-name not available)
    20. 0x00007FFDD919BE1B (UnityPlayer) UnityMain
    21.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFDD8BCA5D3)
    22. 0x00007FFDD8BCA5D3 (UnityPlayer) (function-name not available)
    23.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFDD8BCC7A1)
    24. 0x00007FFDD8BCC7A1 (UnityPlayer) (function-name not available)
    25. 0x00007FFDD9075547 (UnityPlayer) UnityMain
    26. 0x00007FFDD90755E3 (UnityPlayer) UnityMain
    27. 0x00007FFDD9077A3C (UnityPlayer) UnityMain
    28.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFDD8E2680E)
    29. 0x00007FFDD8E2680E (UnityPlayer) (function-name not available)
    30.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFDD8E2556A)
    31. 0x00007FFDD8E2556A (UnityPlayer) (function-name not available)
    32.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FFDD8E2961C)
    33. 0x00007FFDD8E2961C (UnityPlayer) (function-name not available)
    34. 0x00007FFDD8E2D10B (UnityPlayer) UnityMain
    35.   ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF6F5B111F2)
    36. 0x00007FF6F5B111F2 (SlimeRancher) (function-name not available)
    37. 0x00007FFEB58E54E0 (KERNEL32) BaseThreadInitThunk
    38. 0x00007FFEB60A485B (ntdll) RtlUserThreadStart
    39.  
    40. ========== END OF STACKTRACE ===========
     
  7. EnsenaSoft

    EnsenaSoft

    Joined:
    Nov 28, 2012
    Posts:
    13
    We have been trying to find random crashes during scene changes that were happening for our players for a couple of months.

    Both FindObjectsOfType and FindObjectOfType cause random crashes in Awake and sometimes in Start in builds. The only solution we found was to refactor the code to not use them where we could or move to Coroutine and then after a frame. This is a serious issue and a big disappointment and moving them around should not be needed or it should be documented that they should never be used in Awake or Start.
     
  8. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    725
    Any updates here? Kinda ridiculous that essentially a glorified for loop is crashing like this...


    Code (CSharp):
    1. 0   UnityFramework                     0x0000000109cbd83c void std::__1::__sort<CompareInstanceID&, Object**>(Object**, Object**, CompareInstanceID&) (/Users/bokken/build/output/unity/unity/PlatformDependent/iPhonePlayer/External/NonRedistributable/BuildEnvironment/builds/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:3952)
    2. 1   UnityFramework                     0x0000000109cbd8e0 void std::__1::__sort<CompareInstanceID&, Object**>(Object**, Object**, CompareInstanceID&) (/Users/bokken/build/output/unity/unity/PlatformDependent/iPhonePlayer/External/NonRedistributable/BuildEnvironment/builds/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:0)
    3. 2   UnityFramework                     0x0000000109cbd6ac void std::__1::__sort<CompareInstanceID&, Object**>(Object**, Object**, CompareInstanceID&) (/Users/bokken/build/output/unity/unity/PlatformDependent/iPhonePlayer/External/NonRedistributable/BuildEnvironment/builds/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:3995)
    4. 3   UnityFramework                     0x0000000109cbca34 Object::FindObjectsOfType(Unity::Type const*, dynamic_array<Object*, 0ul>&, bool) (/Users/bokken/build/output/unity/unity/Runtime/BaseClasses/BaseObject.cpp:834)
    5. 4   UnityFramework                     0x0000000109f26f28 Scripting::FindObjectsOfType(ScriptingSystemTypeObjectPtr, Scripting::FindMode, bool) (/Users/bokken/build/output/unity/unity/Runtime/Allocator/MemoryMacros.h:283)
    6. 5   UnityFramework                     0x0000000109fc1770 Object_CUSTOM_FindObjectsOfType(ScriptingBackendNativeObjectPtrOpaque*, unsigned char) (/Users/bokken/build/output/unity/unity/artifacts/iOS/Core/iOS_arm64_nondev_i_r/CoreBindings.gen.cpp:54712)
    7. 6   UnityFramework                     0x000000010c6ac430 Object_FindObjectOfType_m3677683526FB4618006B68244D4189A8791C63E8 (/Users/joshuawilde/ProjectGamma/PGiOS/Libraries/libil2cpp/include/codegen/il2cpp-codegen-il2cpp.h:233)
    8. 7   UnityFramework                     0x000000010b4bd848 Object_FindObjectOfType_TisRuntimeObject_m7137356547ADC5089A381F0EC5E9280576983E2E_gshared (/Users/joshuawilde/ProjectGamma/PGiOS/Classes/Native/GenericMethods15.cpp:40662)