Skip to content

[CRITICAL] Game randomly crashes immediately right after pressing play #160

@valkyrienyanko

Description

@valkyrienyanko

The error

ERROR: FATAL: Condition "gchandle.is_released()" is true.
   at: mono_object_disposed_baseref (modules/mono/csharp_script.cpp:1770)
Fatal error. 0xC000001D
   at Godot.NativeInterop.NativeFuncs.godotsharp_internal_refcounted_disposed(IntPtr, IntPtr, Godot.NativeInterop.godot_bool)
   at Godot.GodotObject.Dispose(Boolean)
   at Godot.GodotObject.Finalize()
   at System.GC.RunFinalizers()
Godot Engine v4.4.1.stable.mono.official.49a5bc7b6 - https://godotengine.org
ERROR: System.InvalidOperationException: Handle is not initialized.
   at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
   at Godot.Bridge.CSharpInstanceBridge.SerializeState(IntPtr godotObjectGCHandle, godot_dictionary* propertiesState, godot_dictionary* signalEventsState) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/CSharpInstanceBridge.cs:line 212
   at: void Godot.NativeInterop.ExceptionUtils.LogException(System.Exception) (/root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:113)
Unloading assembly load context...
Vulkan 1.4.308 - Forward+ - Using Device #0: AMD - AMD Radeon RX 6600
Image

Steps to Reproduce

I should note I am unable to reproduce this in Template but the issue does appear in my closed source game which extends from Template so I am not sure if the issue is specifically from Template or my game.

Either way steps to reproduce are as follows:

  1. Make change to some script
  2. Press play
  3. Repeat steps 1 to 2 until the error popup appears

What I'm trying to solve this

I noticed I'm disposing InputEvent in _Input and this is constantly being called whenever there is any input like keyboard input or mouse movement / click inputs. I also do GC.Collect() but it is unrelated since I never used that when this crash occurred, but regardless it will be removed.

@event.Dispose(); // Object count was increasing a lot when this function was executed

@event.Dispose(); // Object count was increasing a lot when this function was executed

GC.Collect(); // Object count was increasing a lot when this function was executed

I did this a while back because I didn't understand the GC and thought the object count increasing from this was a bad thing but then later learned that you do not touch the GC as it handles itself.

I will remove these 3 lines of code and see if the problem persists.

I'm going to assume these are the cause of the issue because when I was working in C on a separate project, double disposing anything would lead to an instant crash.

On a side note I also noticed the ImGui Godot addon calls the Dispose method a lot but I don't think that is the cause of this problem.

Update

The game crashed immediately on pressing play. I didn't have to move or do anything, it happened instantly. This was around with 4th time I pressed play.

Image
Unloading assembly load context...
Assembly load context unloaded successfully.
Godot Engine v4.4.1.stable.mono.official.49a5bc7b6 - https://godotengine.org
Vulkan 1.4.308 - Forward+ - Using Device #0: AMD - AMD Radeon RX 6600

Hello from Example Mod by valkyrienyanko
Godot Engine v4.4.1.stable.mono.official.49a5bc7b6 - https://godotengine.org
ERROR: FATAL: Condition "gchandle.is_released()" is true.
   at: mono_object_disposed_baseref (modules/mono/csharp_script.cpp:1770)
Fatal error. 0xC000001D
   at Godot.NativeInterop.NativeFuncs.godotsharp_internal_refcounted_disposed(IntPtr, IntPtr, Godot.NativeInterop.godot_bool)
   at Godot.GodotObject.Dispose(Boolean)
   at Godot.GodotObject.Finalize()
   at System.GC.RunFinalizers()
ERROR: System.InvalidOperationException: Handle is not initialized.
   at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
   at Godot.Bridge.CSharpInstanceBridge.SerializeState(IntPtr godotObjectGCHandle, godot_dictionary* propertiesState, godot_dictionary* signalEventsState) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/CSharpInstanceBridge.cs:line 212
   at: void Godot.NativeInterop.ExceptionUtils.LogException(System.Exception) (/root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:113)
Unloading assembly load context...
Vulkan 1.4.308 - Forward+ - Using Device #0: AMD - AMD Radeon RX 6600

Update

Looks like the problem may be caused by this line.

using DirAccess dir = DirAccess.Open(modsPath);

I do not think we are suppose to dispose DirAccess.Open like this and no where in the code do I do dir.ListDirEnd();

Removing the using and adding dir.ListDirEnd(); at the very end of the LoadMods() function seems to have solved the issue.

https://docs.godotengine.org/en/stable/classes/class_diraccess.html

Image

Looks like they use using in the docs. So I will try calling dir.Dispose() right after dir.ListDirEnd().

Image Image

Looks like this solved the issue? Not getting the crash anymore.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions