From 925b5abb78695b4587f8b1a030a23ff301809152 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 17 Aug 2023 21:47:02 +0200 Subject: [PATCH] Fix crash on Linux when using unmapped keyboard Keyboard #1321 --- Source/Engine/Input/Input.cpp | 4 ++++ Source/Engine/Platform/Linux/LinuxPlatform.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index 22969c752..81411ed76 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -333,6 +333,8 @@ void Keyboard::OnCharInput(Char c, Window* target) void Keyboard::OnKeyUp(KeyboardKeys key, Window* target) { + if (key >= KeyboardKeys::MAX) + return; Event& e = _queue.AddOne(); e.Type = EventType::KeyUp; e.Target = target; @@ -341,6 +343,8 @@ void Keyboard::OnKeyUp(KeyboardKeys key, Window* target) void Keyboard::OnKeyDown(KeyboardKeys key, Window* target) { + if (key >= KeyboardKeys::MAX) + return; Event& e = _queue.AddOne(); e.Type = EventType::KeyDown; e.Target = target; diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index 0434d8414..5a74d8f68 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -2206,6 +2206,10 @@ bool LinuxPlatform::Init() KeyCodeMap[keyCode] = key; } } + else + { + KeyCodeMap[keyCode] = KeyboardKeys::None; + } } Input::Mouse = Impl::Mouse = New();