Debugging Editor freezes and hangs [Windows Only]

Hi,
We’d like to share a debugging technique with you that will allow you to capture call stacks of the Editor when it is hung up and unresponsive. Attaching these call stacks to your bug reports can in some instances help us figure out where and why things are getting stuck, even if you can’t share your projects or other details with us.

For some time we’ve been testing out an approach that will help show where the editor gets stuck and is compatible with old and new versions of Unity as well.

What, you’ll need:

Then, open up Process Explorer, and in there find Unity.exe with the right parameters (i.e. the one that contains -projectpath [your_project_name])

Inside Process Explorer click on Options → Configure Symbols and point to the right dbghelp.dll from step 2.

The Symbols Path should be the path to the Editor folder for the version of Unity you want to debug (i.e. C:\Program Files\Unity\Hub\Editor[UNITY_VERSION]\Editor\ ). It’s important to select the right version of the Editor because it will use the symbols supplied by the PDB files to figure out the name of the functions being executed. Unfortunately, it cannot resolve call stack frames that are using Mono in them.

Once that is set up, double click Unity.exe in ProcessExplorer, go to the Threads tab, and double click the one that says Unity.exe!WinMainCRTStartup

That will show the current call stack on the main thread in Unity (like in the picture below). Using this call stack can help us figure out what’s going on with the Editor faster, and it might speed up our debugging investigations as well.

Looking forward to helping out and resolving these issues of the editor getting stuck. Please feel free to use this thread to ask questions and discuss the debugging process. Please don’t use it to report your issues. Use the bug reporter for that.

11 Likes

How do I get dbghelp.dll?
I follow your link to the download page and download this: https://go.microsoft.com/fwlink/?linkid=2173743
I open the installer and check the Debugging Tools for Windows

It downloads a bunch of msi files. I click on all of them but nothing happens. Where do I get the dbghelp.dll file?
8112977--1050869--upload_2022-5-9_16-51-37.png

The computer does not have Visual Studio installed

Hey, I’ll update the post with more instructions shortly, but from the link you gave me, the winsdksetup.exe is the file that gets downloaded, and opening it up gives you the choice to install a few things.
If you select the “Debugging Tools For Windows” (refer to pic below) it should then install it in the following location by default:
C:\Program Files (x86)\Windows Kits\10

Then, if you can go to the bin\x64 folder you should find DbgHelp.dll and you can then point Process Explorer to use that: C:\Program Files (x86)\Windows Kits\10\bin\x64\DbgHelp.dll

This looks almost like what you wrote up there, so please let me know if it doesn’t work and I can look into it some more.

1 Like

What if the Unity isn’t hanging or freezing, but crashing instead? I can see crash dumps for my Unity games located here:

%localappdata%\CrashDumps

Would these crash dumps include the Unity symbols? I would presume not, since the symbols are configured to be loaded in Process Explorer? If we need to analyze the crash dumps, how can we make sure that it includes the symbols?

Symbols are located next to Unity.exe in Unity installation directory. You can also point the debugger to our symbol server (https://symbolserver.unity3d.com/). Dumps never include symbols.

1 Like

Having a intermittent “Reloading Domain” issue on 2022.3f1

In this callstack, it looks like something is preventing the domain unload from happening.
Do you have some IDE or a debugger attached? This might be preventing the call from completing.
If you do have a debugger attached, I would recommend updating the package for the debugger in your project to the latest version, since the Visual Studio team has their eye on this sort of race conditions.

Does that help?

I’d also suggest seeing what other threads do. Usually callstack like this indicates that a thread has been started and refuses to finish and Unity must wait for all other C# threads to exit before continuing.

1 Like

It does often happen when debugging, but closing the ide doesn’t help/release the editor.

We have a couple threads running for the game, so that’s likely it.

Any great way to force all accessory game threads to close down when the player stops? (Which is obviously not always a graceful game exit)

Trap an OnApplicationQuit somewhere and force abort them all maybe?

That’s what the editor does, tries aborting them. However, if they are stuck executing native or plugin code, aborting threads may not work (and that’s usually the reason for these complete hangs on domain reloads).

1 Like

this happens for me when debugging in visual studio 2022 community edition , not sure what packages I should update in the package manager as all of them seem already up to date

I had the same issue with debugging → stuck on domain reload.
I was using the asset “Fast Script Reload”, by uninstalling it and set the “AutoRefresh” to “Enabled” in the preferences the problem is now gone and i can debug without the editor getting stucked.
(I should also mention that i am using Unity 2022.3.5f1)

Here’s my stack trace for this pesky bug.
From what I remember this has occured to me multiple times per month, and it was always when I had the debugger attached.
The stack trace did not change after detaching the debugger. It seems like my stack trace ends at the same point as unormal’s trace did, so at “ntdll.dll!RtIUserThreadStart+0x28”, right after Unity has reached the entry points for Windows level stuff.

Hi @Use3rname , thanks for the stack trace.

From what I can see, the editor is trying do to a domain reload but is getting stuck doing it.
What I’ve seen in the past is that some native code, which has been called from managed code, may be doing a long running operation or may be stuck itself too. This prevents Mono from unloading threads as it has to wait for the Native code to come back (Mono can’t terminate native code).

Have you got other threads that are also stuck on “WaitForSingleObject” ? That might help shed some more light on this issue.

Thanks for the insightful reply! My Unity crashed yesterday again, but sadly it was before I got to see your comment.
I’ll take a look at the other threads the next time I get the crash (I’m expecting one within a week or two), and post whatever findings I get into here.

@Unity_Javier Greetings, I have the same issue, I got multiple threads stuck on WaitForSingleObject including the main thread. The question is what do I do with this information? can I somehow get what exactly is being awaited?

Hi, it seems that our Unity 2020.3.47 get’s stucked while compiling mono in debug mode and burst compiler active

I am using Rider which has a unity package and I tried to fiddle with its version. I accidentally forgot to install it and have been running without it for the past day or so, no hangs since and Rider seems to be working fine (serialization, debugger attachment, etc).

Edit: still hangs…

Hi @Gaitorade3D :slight_smile:
If you could share the stack traces then we might be able to determine what is creating this apparent deadlock. To be honest, probably the quickest thing for you to do would be to figure out a certain set of actions that lead to the deadlock and avoid doing them, while we get a fix out into the Editor (for whatever we discover in this convo).

@okluskyond thanks for supplying the stack traces. I can see that they are for 2 separate processes (2952 and 15724) was this during the same session, and if so, was one of them an asset import worker?

Also, the stack traces for the WinMainCRTStartup thread seem incomplete. Usually we would see a bunch of Unity function calls before the Mono. Did you add the path to the editor inside Process Explorer, and set the path to the dbghelp.dll? That would help to understand where in the editor the code is coming from :slight_smile: