From c53d5fd0c841357d4f433fac996b99c0cdc9e415 Mon Sep 17 00:00:00 2001 From: unresolvedsymbol <48220091+unresolvedsymbol@users.noreply.github.com> Date: Tue, 11 Jun 2019 19:06:45 -0500 Subject: [PATCH 1/2] Fix segfault on unknown keys Specifically XF86 keys, which are in 0x10080001+ ranges. When these are passed straight to Keyboard::_states[...] = ... it's definitely not good. --- src/window_eglut.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/window_eglut.cpp b/src/window_eglut.cpp index 13d7aa5..bb51ff4 100644 --- a/src/window_eglut.cpp +++ b/src/window_eglut.cpp @@ -176,6 +176,8 @@ void EGLUTWindow::_eglutKeyboardFunc(char str[5], int action) { int EGLUTWindow::getKeyMinecraft(int keyCode) { // TODO: insert (45), numpad (96-111), numlock (133), scroll (145) + if (keycode > 65535) + return; if (keyCode == 65505 || keyCode == 65506) // left/right shift return 16; if (keyCode == 65507 || keyCode == 65508) // left/right control @@ -225,11 +227,12 @@ int EGLUTWindow::getKeyMinecraft(int keyCode) { void EGLUTWindow::_eglutKeyboardSpecialFunc(int key, int action) { if (currentWindow == nullptr) return; + if (key > 65535) + return; if (key == 65507) currentWindow->modCTRL = (action != EGLUT_KEY_RELEASE); - if (currentWindow->modCTRL && (key == 86 || key == 118) && action == EGLUT_KEY_PRESS) { + if (currentWindow->modCTRL && (key == 86 || key == 118) && action == EGLUT_KEY_PRESS) eglutRequestPaste(); - } int mKey = getKeyMinecraft(key); KeyAction enumAction = (action == EGLUT_KEY_PRESS ? KeyAction::PRESS : (action == EGLUT_KEY_REPEAT ? KeyAction::REPEAT : KeyAction::RELEASE)); @@ -261,4 +264,4 @@ void EGLUTWindow::getWindowSize(int& width, int& height) const { void EGLUTWindow::setClipboardText(std::string const &text) { eglutSetClipboardText(text.c_str()); -} \ No newline at end of file +} From bdb37e33eea2df24b64bdc65816f7092ae64244c Mon Sep 17 00:00:00 2001 From: unresolvedsymbol <48220091+unresolvedsymbol@users.noreply.github.com> Date: Tue, 11 Jun 2019 19:07:59 -0500 Subject: [PATCH 2/2] Wrong method --- src/window_eglut.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/window_eglut.cpp b/src/window_eglut.cpp index bb51ff4..90ac35e 100644 --- a/src/window_eglut.cpp +++ b/src/window_eglut.cpp @@ -176,8 +176,6 @@ void EGLUTWindow::_eglutKeyboardFunc(char str[5], int action) { int EGLUTWindow::getKeyMinecraft(int keyCode) { // TODO: insert (45), numpad (96-111), numlock (133), scroll (145) - if (keycode > 65535) - return; if (keyCode == 65505 || keyCode == 65506) // left/right shift return 16; if (keyCode == 65507 || keyCode == 65508) // left/right control