Csharp glue crash? How do I fix this...

Godot Version

4.4 rc2

Question

I’m getting a crash like this in my game:


ERROR: Unhandled exception
System.ArgumentException: Godot Object not registered. (Parameter 'weakReferenceToSelf')
   at Godot.DisposablesTracker.UnregisterGodotObject(GodotObject godotObject, WeakReference`1 weakReferenceToSelf) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/DisposablesTracker.cs:line 85
   at Godot.GodotObject.Dispose(Boolean disposing) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:line 150
   at Godot.GodotObject.Finalize() in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:line 100
   at: void Godot.NativeInterop.ExceptionUtils.LogUnhandledException(System.Exception) (/root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:132)
Unhandled exception. System.ArgumentException: Godot Object not registered. (Parameter 'weakReferenceToSelf')
   at Godot.DisposablesTracker.UnregisterGodotObject(GodotObject godotObject, WeakReference`1 weakReferenceToSelf) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/DisposablesTracker.cs:line 85
   at Godot.GodotObject.Dispose(Boolean disposing) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:line 150
   at Godot.GodotObject.Finalize() in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:line 100

It happens at a point in my code where I’m cloning a complex graph of objects using FastCloner library.

How do I fix this? I’ve tried a couple of other deepcloning libraries, but this was the only one that fit my needs.

Managed to resolve this. Turns out that cloner library somehow didnt go nicely when it had to clone delegates coming from Godot classes. Worked around it by tuning which fields are cloned and skipping Godot class delegates.