mirror of
https://github.com/godotengine/godot.git
synced 2024-11-26 14:13:10 +00:00
Fix crash on get index for non-existing string
As _buttons and _axes have both valid string and nullptr.
When iterating over them, if given key exists it will work correctly.
But if given key does not exist, it will end up with
String::operator=(nullptr). As String constructor from nullptr exists, I
use it.
(cherry picked from commit c77b710035
)
This commit is contained in:
parent
1a5b379a68
commit
776bca2488
@ -1353,11 +1353,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;
|
||||
}
|
||||
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() {
|
||||
@ -1376,9 +1379,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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user