Search Unity

Bug Headless Server on Windows crashing when trying to use Debug.LogException

Discussion in 'Windows' started by fuego_see_money, Mar 17, 2023.

  1. fuego_see_money

    fuego_see_money

    Joined:
    Jun 11, 2015
    Posts:
    6
    Hey there! I've been running into a crash when catching an `ObjectDisposedException` on my headless server build.

    Code (CSharp):
    1. Uploading Crash Report
    2. ObjectDisposedException: Cannot access a disposed object.
    3. Object name: 'System.Net.Sockets.UdpClient'.
    4.   at System.Net.Sockets.UdpClient.EndReceive (System.IAsyncResult asyncResult, System.Net.IPEndPoint& remoteEP) [0x00013] in <d8cd0ec6fc774382b0a4c707a194e94c>:0
    5.   at CNETServer_Server.UDPReceiveCallback (System.IAsyncResult result) [0x0000c] in <165f234f7f1c435db8c1014fbe63cf2e>:0
    6. UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
    7. UnityEngine.DebugLogHandler:LogException(Exception, Object)
    8. UnityEngine.Logger:LogException(Exception, Object)
    9. UnityEngine.Debug:LogException(Exception)
    10. CNETServer_Server:UDPReceiveCallback(IAsyncResult)
    11. System.Net.Sockets.<>c:<Complete>b__27_0(Object)
    12. System.Threading.QueueUserWorkItemCallback:System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
    13. System.Threading.ThreadPoolWorkQueue:Dispatch()
    14. System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()
    It only appears to be a problem in the headless server build - the program gracefully catches/logs the `ObjectDisposedException` error just fine in the editor server build, as well as the client build in both cases (editor + built player).

    Essentially:
    - Client
    - Editor: no issues
    - Built Player: no issues
    - Server
    - Editor: no issues
    - Built Player (headless): crash

    I attached a zip with the .dmp and .log file - my current Unity version is 2019.1.14f1 (I know, I'm a bit behind) since I've been working on this game for about 3 years now.

    Anyone know how to avoid crashing? I can try just not logging the exception at all, but that seems a bit counterintuitive. I'm trying to have as many helpful logs as possible since my servers are currently running (and also crashing when catching/logging) on Clanforge with Multiplay.

    Any help is greatly appreciated! Thank you!
     

    Attached Files:

  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    It looks like Debug.Log call crashes from a background thread:

    Code (csharp):
    1.      UnityPlayer.dll!memcpy() Line 399   Unknown
    2.      UnityPlayer.dll!core::StringStorageDefault<char>::assign(const char * str, unsigned __int64 strLen)
    3.      UnityPlayer.dll!core::StringStorageDefault<char>::assign(const core::StringStorageDefault<char> & other)
    4.      [Inline Frame] UnityPlayer.dll!core::basic_string<char,core::StringStorageDefault<char>>::assign(const core::basic_string<char,core::StringStorageDefault<char>> &)
    5.      [Inline Frame] UnityPlayer.dll!core::basic_string<char,core::StringStorageDefault<char>>::operator=(const core::basic_string<char,core::StringStorageDefault<char>> &)
    6.      UnityPlayer.dll!CrashReporting::LogBuffer::RecordLogMessage(const core::basic_string<char,core::StringStorageDefault<char>> & message, unsigned __int64 timestamp, unsigned int framecount, LogType type)
    7. >   UnityPlayer.dll!CrashReporting::CrashReporter::HandleLog(const core::basic_string<char,core::StringStorageDefault<char>> & exceptionType, const core::basic_string<char,core::StringStorageDefault<char>> & message, const core::basic_string<char,core::StringStorageDefault<char>> & strippedStacktrace, LogType logType)
    8.      UnityPlayer.dll!CrashReporting::CrashReporter::OnLogCallbackStatic(const DebugStringToFileData & messageData, LogType type, bool isMainThread)
    9.      [Inline Frame] UnityPlayer.dll!CallbackArray3<DebugStringToFileData const &,enum LogType,bool>::Invoke(const DebugStringToFileData &)
    10.      UnityPlayer.dll!DebugStringToFilePostprocessedStacktrace(const DebugStringToFileData & data)
    11.      UnityPlayer.dll!DebugStringToFile(const DebugStringToFileData & data)
    12.      [Inline Frame] UnityPlayer.dll!DebugStringToFile(const char * const &)
    13.      [Inline Frame] UnityPlayer.dll!DebugLogHandler::Internal_Log(LogType)
    14.      UnityPlayer.dll!DebugLogHandler_CUSTOM_Internal_Log(LogType level, LogOption options, ScriptingReferenceWrapper<MonoString *> msg, ScriptingReferenceWrapper<MonoObject *> obj)
    15.  
    Unfortunately it seems like you're on a pretty old version of Unity so even if we fixed it, it wouldn't be in your version of Unity :(.
     
    fuego_see_money likes this.
  3. fuego_see_money

    fuego_see_money

    Joined:
    Jun 11, 2015
    Posts:
    6
    Hey thanks a bunch for looking at it, and for the reply!

    Yeah, I do realize I'm quite a bit behind...about 4 years now...I should have upgraded a while ago, now its to the point where when I tried upgrading I had 999+ errors in the console and a bunch of UI was completely destroyed, so I think there's no going forward with that, at least until I absolutely have to lol ;)

    I think I may just not log the errors for now. It would be nice to have them, but not having them is better than the build crashing! Lol :D

    Cheers!