Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Bug [UWP] CrashReporter crashes the application if you call Debug.LogException() on a different thread.

Discussion in 'Windows' started by livingtarget, Apr 4, 2023.

  1. livingtarget

    livingtarget

    Joined:
    Apr 21, 2015
    Posts:
    83
    Hi,

    We've experienced this bug in the latest Unity 2021 version where players were complaining about crashing when an exception occurred even if it was caught. Thankfully Windows Store now actually records stacktraces, so we could actually figure out why. It's going into GetGfxDevice() which also logs a message alongside the lines of Graphics Device is null before the crash. I assume that GetGfxDevice()/GetCurrentRefreshRate() is not thread safe.

    I've attached the full stacktrace, but here's the relevant snippet:
    "0" "UnityPlayer.dll" "DebugStringToFilePostprocessedStacktrace" "0x000000000000056A"
    "1" "UnityPlayer.dll" "DebugStringToFile" "0x00000000000003C2"
    "2" "UnityPlayer.dll" "DebugStringToFile_core::basic_string_char,core::StringStorageDefault_char_ _ _" "0x000000000000006C"
    "3" "UnityPlayer.dll" "GetGfxDevice" "0x000000000000005B"
    "4" "UnityPlayer.dll" "GetCurrentRefreshRate" "0x0000000000000020"
    "5" "UnityPlayer.dll" "ScreenManagerMetro::GetCurrentResolution" "0x0000000000000031"
    "6" "UnityPlayer.dll" "CrashReporting::CrashReporter::populateReportSharedData" "0x00000000000005D8"
    "7" "UnityPlayer.dll" "CrashReporting::CrashReporter::HandleLog" "0x000000000000037D"
    "8" "UnityPlayer.dll" "CrashReporting::CrashReporter::OnLogCallbackStatic" "0x000000000000001C"

    We've had to disable exception capturing manually on Windows Store as a workaround.
    Code (CSharp):
    1. #if UNITY_WSA
    2.         CrashReportHandler.enableCaptureExceptions = false;
    3. #endif
    It can be reproduced fairly easily, but I am a bit too busy to make a bug report so I'm just going to leave it here.
     

    Attached Files:

  2. reflexing

    reflexing

    Joined:
    Feb 8, 2017
    Posts:
    10
    Got the same for a long time.


    Code (CSharp):
    1.  
    2. Exception thrown at 0x00007FFCD7DF79D6 (UnityPlayer.dll) in Battle Tanks.exe: 0xC0000005: Access violation reading location 0x0000000000001E74.
    3.  
    4.      UnityPlayer.dll!ScreenManagerMetro::GetCurrentResolution(void)    Unknown
    5.      UnityPlayer.dll!CrashReporting::CrashReporter::PopulateReportSharedData(class CrashReporting::CrashReport &,bool)    Unknown
    6.      UnityPlayer.dll!CrashReporting::CrashReporter::HandleLog(char const *,char const *,char const *,enum LogType)    Unknown
    7.      UnityPlayer.dll!CrashReporting::CrashReporter::OnLogCallbackStatic(struct DebugStringToFileData const &,enum LogType,bool)    Unknown
    8.      UnityPlayer.dll!DebugStringToFilePostprocessedStacktrace(struct DebugStringToFileData const &)    Unknown
    9.      UnityPlayer.dll!DebugStringToFile(struct DebugStringToFileData const &)    Unknown
    10.      UnityPlayer.dll!Scripting::LogExceptionFromManaged(class ScriptingExceptionPtr,int,char const *,bool,struct Scripting::LogExceptionFromMangedSettings const *)    Unknown
    11.      UnityPlayer.dll!DebugLogHandler_CUSTOM_Internal_LogException(class ScriptingBackendNativeObjectPtrOpaque *,class ScriptingBackendNativeObjectPtrOpaque *)    Unknown
    12. >    [Inline Frame] GameAssembly.dll!InterfaceActionInvoker2<Exception_t *,Object_tC12DECB6760A7F2CBF65D9DCF18D044C2D97152C *>::Invoke(unsigned short declaringInterface, Il2CppClass *) Line 118    C++
    13.      GameAssembly.dll!SerilogLogHandler_LogException_mF071DDF35A91E490A916AAE5D5F3DFBE079E241A(SerilogLogHandler_tEDA21EDA8180ED91B542BB538B502A4AFDD8042D * __this, Exception_t * ___0_exception, Object_tC12DECB6760A7F2CBF65D9DCF18D044C2D97152C * ___1_context, const MethodInfo * method) Line 6485    C++
    14.      GameAssembly.dll!Logger_LogException_m591AF39F0886DA44666068EDBBD3CCF07623CFBB(Logger_t608FFEA1E140B6BE2CCB01C86ACB219533C172A0 * __this, Exception_t * ___0_exception, Object_tC12DECB6760A7F2CBF65D9DCF18D044C2D97152C * ___1_context, const MethodInfo * method) Line 5500    C++
    15.      GameAssembly.dll!Debug_LogException_mAB3F4DC7297ED8FBB49DAA718B70E59A6B0171B0(Exception_t * ___0_exception, const MethodInfo * method) Line 14771    C++
    16.      GameAssembly.dll!UniTaskScheduler_PublishUnobservedTaskException_m9F6352174ED5654B0A9FB5562B6FF25A788B27D3(Exception_t * ___0_ex, const MethodInfo * method) Line 18410    C++
    17.      GameAssembly.dll!ExceptionHolder_Finalize_m5D7B937A4BDAA2DAE58B962B84BA69DB8C2BEBBF(ExceptionHolder_t877D929A153D46C3BDA043B4058034AF85FB73B1 * __this, const MethodInfo * method) Line 17003    C++
    18.      GameAssembly.dll!il2cpp::vm::Runtime::InvokeWithThrow(const MethodInfo * method, void * obj, void * * params) Line 579    C++
    19.      GameAssembly.dll!il2cpp::vm::Runtime::Invoke(const MethodInfo * method, void * obj, void * * params, Il2CppException * * exc) Line 564    C++
    20.      GameAssembly.dll!il2cpp::gc::GarbageCollector::RunFinalizer(void * obj, void * data) Line 170    C++
    21.      GameAssembly.dll!GC_invoke_finalizers() Line 1318    C
    22.      [Inline Frame] GameAssembly.dll!il2cpp::gc::GarbageCollector::InvokeFinalizers() Line 461    C++
    23.      GameAssembly.dll!il2cpp::gc::FinalizerThread(void * arg) Line 106    C++
    24.      GameAssembly.dll!il2cpp::os::Thread::RunWrapper(void * arg) Line 204    C++
    25.      GameAssembly.dll!il2cpp::os::ThreadStartWrapper(void * arg) Line 29    C++
    26.      [External Code]