godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Confusion about StringName and it's constructor that takes a boolean

Open xana43 opened this issue 10 months ago • 0 comments

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<int>(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

xana43 avatar Dec 26 '24 18:12 xana43