godot: .NET 6: The game crashes on System.AccessViolationException

Godot version

v4.0.beta1.mono.official [4ba934bf3]

System information

Windows 11, 3080Ti, Vulkan mobile

Issue description

I’m making a shooter game. When there are many node instances been created for bullets, the game player crashes with the following log printed in verbose mode:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Godot.NativeInterop.NativeFuncs.godotsharp_variant_destroy(Godot.NativeInterop.godot_variant ByRef)
   at Godot.NativeInterop.godot_variant.Dispose()
   at Godot.Variant+Disposer.Dispose(Boolean)
   at Godot.Variant+Disposer.Finalize()

Steps to reproduce

  1. Run godot with --editor --verbose
  2. Open the attached project
  3. Run the game
  4. Hold left mouse button to start shooting knifes. Wait for a while (~ 20 seconds) and it’ll eventually crash.
  5. Check the terminal log for the error message. NO ERRORS ARE SHOWN in editor

Minimal reproduction project

bug-mem-violation.zip

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 6
  • Comments: 18 (10 by maintainers)

Most upvoted comments

Since beta 4 this constructor was replaced with a static method: Callable.From. (https://github.com/godotengine/godot/pull/67987)

Callable.From((Projectile projectile) =>
{
    AddChild(projectile);
    projectile.GlobalPosition = Muzzle.GlobalPosition;
    projectile.ZIndex = 1;
}).CallDeferred(projectile);