Closed TokageItLab closed 1 year ago
StringName
compares by pointer, as you mentioned the appropriate way to do that is to use StringName::AlphCompare
, the reason why StringName
compares this way is performance, and the order will be stable, though newer names might end up before older ones depending on allocations
Closed by #79595.
Godot version
4.1
System information
Any
Issue description
Perhaps because the entity of
StringName
is a memory address, the order ofStringName
is not unique when it is used as a key inRBMap
.RBMap<StringName, V>
is used in several classes/places:There are two ways to solve this problem, and we should choose one of them depends on each case:
RBMap<StringName, V>
workIs it correct way to go implicitly converting StringName to String in RBMap?RBMap<StringName, V, StringName::AlphCompare>
can be usedRBMap<StringName, V>
in some classes withHashMap<StringName, V>
orRBMap<String, V>
Steps to reproduce
If you run the following code anywhere, you can see that the order changes each time Godot is launched.
Minimal reproduction project
RBMap
is a C++ class and is not exported to gdscript, so there is no project. Run the above code in any.cpp
.