From dd307cc23e643c74b4b117509248c48dcf301f4b Mon Sep 17 00:00:00 2001 From: Marco Antognini Date: Wed, 8 Nov 2017 15:25:55 +0100 Subject: [PATCH] Fixed crash with application messing hardware detection This prevents crashes & reduces the amount of logging but does not actually make isKeyPressed work when using e.g. TeamViewer. --- src/SFML/Window/OSX/HIDInputManager.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SFML/Window/OSX/HIDInputManager.mm b/src/SFML/Window/OSX/HIDInputManager.mm index c74200ce8..d11c90928 100644 --- a/src/SFML/Window/OSX/HIDInputManager.mm +++ b/src/SFML/Window/OSX/HIDInputManager.mm @@ -152,6 +152,7 @@ void HIDInputManager::initializeKeyboard() CFSetRef keyboards = copyDevices(kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard); if (keyboards == NULL) { + sf::err() << "No keyboard detected by the HID manager!" << std::endl; freeUp(); return; } @@ -313,9 +314,11 @@ void HIDInputManager::freeUp() if (m_layoutData != 0) CFRelease(m_layoutData); + m_layoutData = 0; // Do not release m_layout! It is owned by m_layoutData. if (m_manager != 0) CFRelease(m_manager); + m_manager = 0; for (unsigned int i = 0; i < Keyboard::KeyCount; ++i) { @@ -355,11 +358,8 @@ CFSetRef HIDInputManager::copyDevices(UInt32 page, UInt32 usage) bool HIDInputManager::isPressed(IOHIDElements& elements) { - if (!m_isValid) - { - sf::err() << "HIDInputManager is invalid." << std::endl; + if (!m_isValid) return false; - } // state = true if at least one corresponding HID button is pressed bool state = false;