Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xana43 opened this issue Dec 26, 2024 · 0 comments
Open

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

xana43 opened this issue Dec 26, 2024 · 0 comments

Comments

@xana43
Copy link

xana43 commented Dec 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant