godotengine / godotengine/godot
GDExtension: Unable to add_resource_format_loader
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible with Godot 4.2.1 and godot-cpp 4.2.
### System information
Godot v4.2.1.stable - Windows 10.0.22631 - Vulkan (Forward+) - integrated Intel(R) Iris(R) Xe Graphics (Intel Corporation; 31.0.101.4889) - 12th Gen Intel(R) Core(TM) i7-1280P (20 Threads)
### Issue description
Following [this](https://docs.godotengine.org/en/stable/contributing/development/core_and_modules/custom_resource_format_loaders.html) official guide and making note of this [proposal](https://github.com/godotengine/godot-proposals/issues/4548), it should be possible to register custom ResourceLoader's within a GDExtension. I've checked and triple checked that I haven't missed anything, following the JSON and Image implementation of `ResourceFormatLoader` under `godot/core/io/` verbatim. The project I'm working on implementing this in is open-source, and the files of interest are as follows:
- [RegisterExtension.cpp](https://github.com/Ardos-Project/godot-dcparser/blob/working-version/src/RegisterExtension.cpp)
- DCFileLoader.([h](https://github.com/Ardos-Project/godot-dcparser/blob/working-version/src/DCFileLoader.h)/[cpp](https://github.com/Ardos-Project/godot-dcparser/blob/working-version/src/DCFileLoader.cpp))
- DCFileResource.([h](https://github.com/Ardos-Project/godot-dcparser/blob/working-version/src/DCFileResource.h)/[cpp](https://github.com/Ardos-Project/godot-dcparser/blob/working-version/src/DCFileResource.cpp))
When attempting to debug this, calling `print(ResourceLoader.get_recognized_extensions_for_type("DC"))` within a GDScript file returns `["tres"]`, when it should return `["tres", "dc"]`. Calling the same code with `"JSON"` instead returns `["tres", "res", "json"]`
Other functions of the GDExtension work fine, as can be seen [here](https://github.com/Ardos-Project/godot-dcparser/blob/working-version/project/scenes/demo.gd), it's just the custom ResourceLoader I'm having issues with.
Any help would be greatly appreciated!
### Steps to reproduce
The MRP contains the compiled extension for windows as well as the demo code that causes the debugger to error with: `E 0:00:00:0541 demo.gd:7 @ _ready(): No loader found for resource: res://data/example.dc (expected type: )
Method/function failed. Returning: Ref()
core/io/resource_loader.cpp:282 @ _load()
demo.gd:7 @ _ready()
`
### Minimal reproduction project (MRP)
[MRP.zip](https://github.com/godotengine/godot/files/14093035/MRP.zip)
Contributor guide
Assessment
This issue has not been assessed yet.