godotengine / godotengine/godot
C# `_GetPropertyList` return a Callable to the `Clear` method, instead of a custom-made `Clear` property
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
v4.2.1.stable.mono.official [b09f793f5]
### System information
Godot v4.2.1.stable.mono - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3080 (NVIDIA; 31.0.15.3640) - Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz (12 Threads)
### Issue description
When exporting a long list of properties in a custom Resource in C# using `_GetPropertyList`, that also implements the `IDictionary` interface, I encounter the following error whenever I try to create an instance of the Resource or open one in the inspector:
```
ERROR: BUG: Unreferenced static string to 0: Clear
at: unref (core/string/string_name.cpp:129)
```
I don't know the exact number of properties that causes this, but I know it's more than 23 (the number of constants defined by the `JoyButton` enum) and no more than 193 (the number of constants defined by the `Key` enum).
### Steps to reproduce
Create a new C# script that extends `Resource` and `IDictionary`, then override `_GetPropertyList`, `_Get`, and `_Set` in the new Resource such that the number of properties is large (making it 193 items, such as by using the names of the `Key` enum constants, will trigger this).
Build, then create an instance of the new Resource. After a few seconds, the above error will appear in the output window and Godot may crash. In my experience, deleting the `%APPDATA%/Godot` directory temporarily fixes the crash, but eventually it will start crashing every time this error occurs.
### Minimal reproduction project (MRP)
[Test.zip](https://github.com/godotengine/godot/files/13924013/Test.zip)
Contributor guide
Research direction
Start with the attached Test.zip minimal reproduction and inspect the C# Resource implementing IDictionary, especially its _GetPropertyList, _Get, and _Set overrides. Reproduce the large-property case using the Key enum names, then trace how the Clear member is exposed. Done means creating or opening the Resource no longer reports the unreferenced static string error or crashes, with Clear represented as the method Callable described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, godot
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100