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

[3.x] Fix crash on get_joy_button_index_from_string and get_joy_axis_index_from_string for non-existing key #59195

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions main/input_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,11 +1338,14 @@ String InputDefault::get_joy_button_string(int p_button) {

int InputDefault::get_joy_button_index_from_string(String p_button) {
for (int i = 0; i < JOY_BUTTON_MAX; i++) {
if (p_button == _buttons[i]) {
if (_buttons[i] == nullptr) {
break;
akien-mga marked this conversation as resolved.
Show resolved Hide resolved
}
if (p_button == String(_buttons[i])) {
return i;
}
}
ERR_FAIL_V(-1);
ERR_FAIL_V_MSG(-1, vformat("Could not find a button index matching the string \"%s\".", p_button));
}

int InputDefault::get_unused_joy_id() {
Expand All @@ -1361,9 +1364,12 @@ String InputDefault::get_joy_axis_string(int p_axis) {

int InputDefault::get_joy_axis_index_from_string(String p_axis) {
for (int i = 0; i < JOY_AXIS_MAX; i++) {
if (p_axis == _axes[i]) {
if (_axes[i] == nullptr) {
break;
}
if (p_axis == String(_axes[i])) {
return i;
}
}
ERR_FAIL_V(-1);
ERR_FAIL_V_MSG(-1, vformat("Could not find an axis index matching the string \"%s\".", p_axis));
}