From 130fd653a4101331fc900137a2161893ac37cbe1 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Mon, 21 Mar 2022 20:09:01 +0100 Subject: [PATCH] Prevent Char-to-code crash (#6392) --- core/src/com/unciv/ui/utils/KeyPressDispatcher.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/ui/utils/KeyPressDispatcher.kt b/core/src/com/unciv/ui/utils/KeyPressDispatcher.kt index 1c12a709b1..0ff608f2ac 100644 --- a/core/src/com/unciv/ui/utils/KeyPressDispatcher.kt +++ b/core/src/com/unciv/ui/utils/KeyPressDispatcher.kt @@ -64,7 +64,15 @@ data class KeyCharAndCode(val char: Char, val code: Int) { val UNKNOWN = KeyCharAndCode(Input.Keys.UNKNOWN) /** mini-factory for control codes - case insensitive */ - fun ctrl(letter: Char) = KeyCharAndCode(Char(letter.code and 31), 0) + fun ctrl(letter: Char) = KeyCharAndCode(Char( + try { + letter.code and 31 + } catch (ex: NoSuchMethodError) { + // Seems to happen on some Ubuntu systems + @Suppress("DEPRECATION") + letter.toInt() and 31 + } + ), 0) /** mini-factory for control codes from keyCodes */ fun ctrlFromCode(keyCode: Int): KeyCharAndCode {