Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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

Discussion in 'Editor & General Support' started by Sparticus, Sep 14, 2022.

  1. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    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.


    Code (CSharp):
    1. Release of invalid GC handle. The handle is from a previous domain. The release operation is skipped.
    2. UnityEditor.SceneManagement.EditorSceneManager:OpenScene (string)
    3. SceneAutoLoader:OnPlayModeChanged (UnityEditor.PlayModeStateChange) (at Assets/Editor/SceneAutoLoader.cs:100)
    4. 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?
     
    Ony, unityventures13 and StamIAm like this.
  2. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    188
    Having this all the time, too
     
    Ony and unityventures13 like this.
  3. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    226
    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. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    I am still having this error. I also recently upgraded Unity. Anyone figure out a solution?
     
  5. dyamanoha_

    dyamanoha_

    Joined:
    Mar 17, 2013
    Posts:
    78
  6. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
  7. gamegamesgamedev

    gamegamesgamedev

    Joined:
    Aug 2, 2020
    Posts:
    3
    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?
     
    Last edited: Sep 29, 2022
  8. gamegamesgamedev

    gamegamesgamedev

    Joined:
    Aug 2, 2020
    Posts:
    3
    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.
     
    Last edited: Sep 29, 2022
  9. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    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 :(
     
    nebyu1 and Ony like this.
  10. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,948
    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
    Code (csharp):
    1.  
    2. if (Application.isPlaying){
    3.      EditorSceneManager.OpenScene(PreviousScene);
    4. }
    5.  
    and see if fixes it
     
    unity_KxrL7spM5mfkGQ likes this.
  11. JuanJesusLigero

    JuanJesusLigero

    Joined:
    Oct 5, 2022
    Posts:
    1
    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 :)
     
  12. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    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.
     
    IgorAherne, Malbers, jimisv52 and 2 others like this.
  13. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,015
    Does this happen on a fresh project or just your current project?
     
  14. Sparticus

    Sparticus

    Joined:
    Mar 15, 2014
    Posts:
    149
    I tried creating a fresh empty project and I do not see the same error. So I am not sure what to do :(
     
  15. trunghieu95tb

    trunghieu95tb

    Joined:
    Nov 2, 2016
    Posts:
    1


    Turn off the scene light and problem solved.
     

    Attached Files:

  16. PoyriBariskan

    PoyriBariskan

    Joined:
    Sep 29, 2022
    Posts:
    1
    it worked, thanks
     
  17. CrazyJ0hn

    CrazyJ0hn

    Joined:
    Jan 23, 2023
    Posts:
    1
    I get this error when trying to publish as a webgl anybody know how to fix
     
  18. GameActuator

    GameActuator

    Joined:
    Jul 16, 2022
    Posts:
    10
    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.
     
  19. Ram-Apprlabs

    Ram-Apprlabs

    Joined:
    Apr 19, 2022
    Posts:
    10
    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
     
  20. MarkSteere

    MarkSteere

    Joined:
    Dec 31, 2022
    Posts:
    54
    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.
     
  21. vperelygin

    vperelygin

    Joined:
    Dec 5, 2016
    Posts:
    1
    "Format Document" in Visual Studio solved the problem
     
  22. yolomobile

    yolomobile

    Joined:
    Jan 13, 2023
    Posts:
    3
    We Love You ...
     
  23. chixiguabutuputaopi

    chixiguabutuputaopi

    Joined:
    Apr 12, 2023
    Posts:
    1
    nice
     
  24. terencepek

    terencepek

    Joined:
    Oct 20, 2022
    Posts:
    1
    Last edited: Apr 14, 2023
    MaciekOaky and KNKJ21 like this.
  25. MaciekOaky

    MaciekOaky

    Joined:
    Nov 10, 2016
    Posts:
    6
    @terencepek thank you for the article. It solved the issue on my end :)
     
  26. ma2likh

    ma2likh

    Joined:
    Sep 17, 2022
    Posts:
    1

    what kind of sorcery is this bro .it worked !!
     
  27. artyrmsergeev

    artyrmsergeev

    Joined:
    Saturday
    Posts:
    1
    I had that pesky error. I happen to use git to control versions of my project (really helpful). So I tried to remove all uncommitted changes (you might want to backup them as well). Among them were files autogenerated with Unity:
    - Some .meta files for fbx files of my scene.
    - manifest.json and packages.json in /Packages folder
    - GvhProjectSettings.xml in ProjectSettings folder.

    I removed all of these and the problem is gone, and Unity recreated those files.