godotengine / godotengine/godot-cpp
Confusion about StringName and it's constructor that takes a boolean
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
### Godot version
v4.3.1.rc.custom_build [b51be503c]
### godot-cpp version
4.3.stable
### System information
Fedora 41
### Issue description
In order to make certain constants faster for comparison, I made static arrays of StringName I.E.
```
namespace godot::KeyConstants{
enum class KEY_CONSTANTS{
FORWARD,
BACKWARD,
LEFT,
RIGHT
}
_NO_DISCARD extern const StringName& getKeyAction(KEY_CONSTANTS action);
}
//in the cpp file
namespace godot{
const StringName& KeyConstants::getKeyAction(const KEY_ACTIONS action)
{
static const StringName actionNames[]{
{"forward",true},
{"backward",true},
{"left",true},
{"right",true}
}
return actionNames[static_cast(action)];
}
}
```
this all works fine during runtime, but when I exit the editor or the game after these have been loaded, I get this error
```
ERROR: BUG: Unreferenced static string to 0: forward
at: unref (./core/string/string_name.cpp:120)
ERROR: BUG: Unreferenced static string to 0: backward
at: unref (./core/string/string_name.cpp:120)
ERROR: BUG: Unreferenced static string to 0: left
at: unref (./core/string/string_name.cpp:120)
ERROR: BUG: Unreferenced static string to 0: right
at: unref (./core/string/string_name.cpp:120)
```
what am I doing wrong here?
### Steps to reproduce
create a local static variable of type StringName using the StringName(const char*,bool) constructor with the bool being true. (local static because it seems like trying to do global static causes a crash)
close or otherwise reload the extension.
### Minimal reproduction project
N/A
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.