inexorgame / vulkan-renderer

A new 3D game engine for Linux and Windows using C++20 and Vulkan API 1.3, in very early but ongoing development
https://inexor.org
MIT License
790 stars 34 forks source link

[input] Ignore invalid key ids and button ids #421

Closed IAmNotHanni closed 3 years ago

IAmNotHanni commented 3 years ago

Closes #410

Thank you @westernheld for finding this issue!

yeetari commented 3 years ago

I feel like the

if (key < 0 || key > GLFW_KEY_LAST) {
    return;
}

should be moved to the GLFW callback before it calls press_key and release_key, and the user facing functions should still have asserts.

To address your comment on discord:

but the .at method would have saved us, right?

Yes, because the assert didn't trigger since it was operating on a signed int, so I think that the functions in keyboard_mouse_data.cpp should take in uint32_ts instead (which should be ok since the GLFW_KEY_s are defines), and the GLFW callback can cast the int is receives.