Fixed Linux crash caused by wrong mapping of key codes.

This commit is contained in:
Sebastian 2020-09-20 23:31:45 +01:00
parent 860b922206
commit ea74c3c872
3 changed files with 22 additions and 13 deletions

View File

@ -11,6 +11,7 @@ Improving stability
- Improved hot-reload stability and support for reloading after recompiling outside of the editor. Both methods should be equally supported and work together. - Improved hot-reload stability and support for reloading after recompiling outside of the editor. Both methods should be equally supported and work together.
- Improved behaviour of delegates when hot-reloading. - Improved behaviour of delegates when hot-reloading.
- Changed context index mapping to fix issues with multi-PIE debugging in 4.25. - Changed context index mapping to fix issues with multi-PIE debugging in 4.25.
- Fixed Linux crash caused by wrong mapping of key codes.
Version: 1.20 (2020/06) Version: 1.20 (2020/06)
Transition to IWYU and maintenance: Transition to IWYU and maintenance:

View File

@ -122,6 +122,17 @@ namespace ImGuiInterops
Copy(Mapping.KeyMap, IO.KeyMap); Copy(Mapping.KeyMap, IO.KeyMap);
} }
// Simple transform mapping key codes to 0-511 range used in ImGui.
// From what I can tell, on most supported platforms key codes should comfortably fit in that range anyway
// but the SDL key-codes used on Linux can go way out of this range (because of the extra flag). However,
// after this transform they should fit in the range without conflicts.
// NOTE: Should any of the platforms have other conflicts or any trouble with inputs, this is the likely
// candidate for change.
static uint32 MapKeyCode(uint32 KeyCode)
{
return (KeyCode < 512) ? KeyCode : 256 + (KeyCode % 256);
}
uint32 GetKeyIndex(const FKey& Key) uint32 GetKeyIndex(const FKey& Key)
{ {
const uint32* pKeyCode = nullptr; const uint32* pKeyCode = nullptr;
@ -129,17 +140,17 @@ namespace ImGuiInterops
FInputKeyManager::Get().GetCodesFromKey(Key, pKeyCode, pCharCode); FInputKeyManager::Get().GetCodesFromKey(Key, pKeyCode, pCharCode);
if (pKeyCode) const uint32 KeyCode =
{ pKeyCode ? *pKeyCode
return *pKeyCode; : pCharCode ? *pCharCode
} : 0;
if (pCharCode) return MapKeyCode(KeyCode);
{ }
return *pCharCode;
}
return 0; uint32 GetKeyIndex(const FKeyEvent& KeyEvent)
{
return MapKeyCode(KeyEvent.GetKeyCode());
} }
uint32 GetMouseIndex(const FKey& MouseButton) uint32 GetMouseIndex(const FKey& MouseButton)

View File

@ -40,10 +40,7 @@ namespace ImGuiInterops
uint32 GetKeyIndex(const FKey& Key); uint32 GetKeyIndex(const FKey& Key);
// Map key event to index in keys buffer. // Map key event to index in keys buffer.
FORCEINLINE uint32 GetKeyIndex(const FKeyEvent& KeyEvent) uint32 GetKeyIndex(const FKeyEvent& KeyEvent);
{
return KeyEvent.GetKeyCode();
}
// Map mouse FKey to index in mouse buttons buffer. // Map mouse FKey to index in mouse buttons buffer.
uint32 GetMouseIndex(const FKey& MouseButton); uint32 GetMouseIndex(const FKey& MouseButton);