CesiumGS / cesium-unity

Bringing the 3D geospatial ecosystem to Unity
https://cesium.com/platform/cesium-for-unity/
Apache License 2.0
320 stars 75 forks source link

Investigate "Release of invalid GC handle" errors #318

Open csciguy8 opened 1 year ago

csciguy8 commented 1 year ago

Install Unity Hub 3.4.2 and Unity 2021.3.25f1.

Follow the 'Cesium for Unity Quickstart" guide, https://cesium.com/learn/unity/unity-quickstart/

1) Create a new project, use the "3D Sample Scene (HDRP)" template. 2) Add the Cesium scoped registry to the Project Settings 3) Install Cesium from the Package Manager (Cesium for Unity, Version 1.2.0 - May 09, 2023) Note a warning in the console:

The package cache was invalidated and rebuilt because the following immutable asset(s) were unexpectedly altered:
      Packages/com.unity.render-pipelines.highdefinition/Runtime/RenderPipelineResources/HDRenderPipelineRuntimeResources.asset
      Packages/com.cesium.unity/Runtime/Resources/CesiumDefaultTilesetMaterial.mat
      Packages/com.cesium.unity/Runtime/Resources/CesiumUnlitTilesetMaterial.mat

4) From the main menu, select Cesium -> Cesium to bring up the Cesium window (opens next to hierarchy) 5) Close Unity 6) Open your project again.

You'll see two console errors on startup. Release of invalid GC handle. The handle is from a previous domain. The release operation is skipped.

The error persists every time you open your project and the Cesium Window is present.

Note: This does not happen if using the "3D Sample Scene (URP)" template

j9liu commented 2 months ago

This is an old issue, but I'm repurposing it for a recent trend of these memory-related errors.

On the forum, a user noticed this error come up while viewing 02_CesiumMelbourne in cesium-unity-samples. I could see the same error come up in that level after entering / exiting play mode.

Additionally, other users on this forum thread have posted that their system memory keeps climbing in the Unity editor. One user reports:

Hi, I have encountered this before. It has something to do with Cesium updating in the editor. Just untick the “Update in Editor” and that should fix the problem for now. Not really a fix, but eliminates that problem.

This makes me suspect that the two are related. Maybe we aren't properly handling the life cycle in Edit mode, somehow, and the memory leaks are accumulating over time. Just a hunch though, this warrants more thorough investigating.