godotengine / godotengine/godot

[3.x] Task.Delay throws NullReferenceException on HTML5 exports

Open
#100,740 1 comment 0 reactions 0 assignees View on GitHub
bug platform:web
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

Reproducible in: v3.6.stable.mono.official [de2f0f147]
* Occurs both when "Export as Debug" is set and when it isn't.
* Does *not* occur on Windows exports

### System information

Windows 11 64-bit, Chrome 131.0.6778.205

### Issue description

Awaiting `Task.Delay` works fine in editor builds, but crashes on HTML5 exports, showing the following message on the console (F12):

> Unhandled Exception:
> System.NullReferenceException: Object reference not set to an instance of an object.
> at System.Threading.WasmRuntime.TimeoutCallback (System.Int32 id) <0x2f69080 + 0x0000a> in :0
> timeout callback threw a System.NullReferenceException

### Steps to reproduce

* Open the attached minimal reproduction project in Godot
* It contains a single script:
```csharp
public override void _Ready() {
Task.Run(async () => {
GD.Print("Waiting...");
await Task.Delay(1000);
GD.Print("Done");
});
}
```
* Observe how it runs as expected in the editor
* Export to HTML5, then run `python -m http.server` when `cd`-d into the exported directory
* Browse `http://localhost:8000`, press F12 to keep the console window open
* Click `TaskDelayDemo.html` and observe the errors in the console, and that "Done" is never printed

### Minimal reproduction project (MRP)

[TaskDelayDemo.zip](https://github.com/user-attachments/files/18221915/TaskDelayDemo.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.