Skip to content

C# "Cannot access a disposed object." when calling Time.GetTicksMsec() from a background thread #101170

@Avantir-Chaosfire

Description

@Avantir-Chaosfire

Tested versions

4.3.stable.mono.official

System information

macOS 14.6.1

Issue description

Cannot access a disposed object.
Object name: 'Godot.TimeInstance'. -    at Godot.GodotObject.GetPtr(GodotObject instance) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:line 78
   at Godot.Time.GetTicksMsec() in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Time.cs:line 349

As you can see I'm getting this error when calling Time.GetTicksMsec() in C#. However, I am calling this in a background thread (not the physics thread) that is initiated at application startup, from the end of the scene tree's root node's _Ready() method. The background thread repeatedly calls this method, but it seems like it only gets this error right at the beginning.

Is this expected behaviour? Is it safe to call Time.GetTicksMsec() from a thread other than the physics thread?

Edit: I'm seeing this same behaviour with other system methods too. The documentation seems to indicate this should work? Is it possible this issue is because I'm using C# and not GDScript (because I see the error is coming from the C# wrapper)?

Steps to reproduce

Not adding this for now, as I'm not clear that this is a bug that needs fixing.

Minimal reproduction project (MRP)

Not adding this for now, as I'm not clear that this is a bug that needs fixing.

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