godotengine / godotengine/godot

ResourceLoader::LoadToken leaks

Open
#102,476 3 comments 0 reactions 0 assignees View on GitHub
discussion documentation topic:core
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

4.3-stable

### System information

Windows 11

### Issue description

Calling `ResourceLoader.load_threaded_request` without `ResourceLoader.load_threaded_get` causes leaks of `ResourceLoader::LoadToken`.
```gdscript
extends Node2D

const path := "res://icon.svg"
var finished := false

func _ready() -> void:
var err := ResourceLoader.load_threaded_request(path, "", true, ResourceLoader.CACHE_MODE_IGNORE)
print("load_threaded_request: %s" % error_string(err))

func _process(delta: float) -> void:
if (finished):
return

var status = ResourceLoader.load_threaded_get_status(path)
if (status != ResourceLoader.THREAD_LOAD_IN_PROGRESS):
finished = true
# without the following line, a ResourceLoader.LoadToken will be leaked
# ResourceLoader.load_threaded_get(path)
print("loaded")

```

I don't know whether it's expected behavior or not?

### Steps to reproduce

Run the project scene from godot editor executable with parameters:
` --verbose --path "PATH_TO_PROJECT/resource_loader_test" res://node_2d.tscn`

*ObjectDB::cleanup()* will report a leaked instance which is a `ResourceLoader::LoadToken`.

### Minimal reproduction project (MRP)

[resource_loader_test.zip](https://github.com/user-attachments/files/18688297/resource_loader_test.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.