Release of invalid GC handle. Oh my, what have I done?

Hey all,

I have been working on a game for almost 2 years now. Just the other day I started getting an error every single time I stop playing the game within the Unity IDE.

Release of invalid GC handle. The handle is from a previous domain. The release operation is skipped.
UnityEditor.SceneManagement.EditorSceneManager:OpenScene (string)
SceneAutoLoader:OnPlayModeChanged (UnityEditor.PlayModeStateChange) (at Assets/Editor/SceneAutoLoader.cs:100)
UnityEditor.EditorApplication:Internal_PlayModeStateChanged (UnityEditor.PlayModeStateChange)

I have no idea what I added or did to the game to cause this. The ā€˜SceneAutoLoader.csā€™ is not my codeā€¦ the code on line 100 is :

EditorSceneManager.OpenScene(PreviousScene);

Any idea what I have done to cause this?

3 Likes

Having this all the time, too

2 Likes

We have this since updating our project to 2021.3.10 yesterday. I dont have a stacktrace only the error.
No idea what is going onā€¦

4 Likes

I am still having this error. I also recently upgraded Unity. Anyone figure out a solution?

Same

I see someone else submitted a bug report 6 days ago. I feel this is a newly introduce bug in Unity. Any post regarding it is quite new. Would be great to hear of a fix for this :frowning:

I also updated my Unity to v.2020.3.39f1, which is a Long Term Support version. This bug has totally derailed my plans. And being new to gamedev, Iā€™m not sure how to move forward. Does anyone have any suggestions as to how I can build my game even with this error?

UPDATE: I realized that I had a bunch of build errors and they pointed to an autosave script from Tarodev (https://github.com/Matthew-J-Spencer/Unity-AutoSave). After removing it, I am finally able to build the game! The ā€œResolve of invalid GC Handleā€ error is still happening during preview, but at least itā€™s not happening when trying to build.

So still a month later I still get this error every single time I finish running the game. Anyone know if itā€™s safe to just ignore the error? I feel gross seeing this red error every time the game endsā€¦ I see many people with this issue lately as it seems to be a new unity bug. Yet, no one has a solution :frowning:

2 Likes

This happens after exit play mode ?

In this case why would the code that loads a scene be executed at all, since you left the game, that is one thing to consider.

Try add a check like

if (Application.isPlaying){
     EditorSceneManager.OpenScene(PreviousScene);
}

and see if fixes it

1 Like

This ā€œResolve of invalid GC handleā€ error also suddenly started happening to me when exiting play mode. After a while I realized that some parts of my code had different line endings (Windows style and Unix style), so I went and changed all the EOL to Windows style (I used notepad++), and that somehow solved the problem :slight_smile:

Update: I think I have finally figured out how to reproduce the issue 100% of the time. I am really hoping to get someone from Unity to respond ( @JeffDUnity3D possibly).

The error message :
Release of invalid GC handle. The handle is from a previous domain. The release operation is skipped.

How to reproduce :
1.) Run your game in the Unity Editor
2.) Make changes to the game code while the game is running
3.) Save your code and then go back to Unity. Stop the game from running. At this point when the game stops running, I have Unity set to re-import code changes (it checks for errors in your code at this time).
4.) 100% of the time Unity will report the above error

If you run your game and do not make changes to the code, the error never happens.

5 Likes

Does this happen on a fresh project or just your current project?

I tried creating a fresh empty project and I do not see the same error. So I am not sure what to do :frowning:

Turn off the scene light and problem solved.

8674407--1168929--upload_2022-12-20_9-22-43.png

9 Likes

it worked, thanks

1 Like

I get this error when trying to publish as a webgl anybody know how to fix

Resolve of invalid GC handle. The handle is from a previous domain. The resolve operation is skipped.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Trying to recreate this error but I cannot find a constant on my end.

I get it when:
Editing script when I have the script open in Unity
(This was the first instance I saw it happen. Now the error happens all the time)
Creating a 3D plane in a new project (No new assets, no new installs, just create>3D>Plane)
When importing some assets from the asset store
When deleting the main camera or adding a new camera

Double clicking the error does nothing, normally it takes you to the location of the error if itā€™s in a script. It seems like others donā€™t have negative results with GC handle errors but I hate seeing an error in the console I cannot fix.

Actually i got this error from export another project data to current project and the two projects(AR & 3D) have different versions maybe reason its come to me. but what i do now

I got this error after I deleted a resource image and replaced it with a new one. The image had been used as the source image of a button. I deleted the image from the button and re-installed it. Then the error disappeared.