Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [OSX] keyboard problem (related: sf::isKeyPressed(Key key) )  (Read 1808 times)

0 Members and 1 Guest are viewing this topic.

cordis3

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
[OSX] keyboard problem (related: sf::isKeyPressed(Key key) )
« on: August 20, 2013, 11:10:34 am »
I'm using sfml 2.0 for developing my game. Game development is almost finished and I've been looking for some bugs and fixing them these days.

I've got SEGFAULT from sf:Keyboard::isKeyPressed. Typically, in normal case, keyboards inputs are well processed and exactly recognize what key is pressed. But after turn off and on my keyboard(apple wireless keyboard), my game is crashed.

bool HIDInputManager::isKeyPressed(Keyboard::Key key)
{
    if (!m_isValid) {
        sf::err() << "HIDInputManager is invalid." << std::endl;
        return false;
    }
   
    // state = true if at least one corresponding HID key is pressed
    bool state = false;
   
    for (IOHIDElements::iterator it = m_keys[key].begin(); it != m_keys[key].end(); ++it) {
       
        IOHIDValueRef value = 0;
       
        IOHIDDeviceRef device = IOHIDElementGetDevice(*it);
        IOHIDDeviceGetValue(device, *it, &value);
       
        if (!value) {
           
            // This means some kind of error / deconnection so we remove this
            // element from our keys
           
            CFRelease(*it);
            it = m_keys[key].erase(it);
                       
        } else if (IOHIDValueGetIntegerValue(value) == 1) {
           
            // This means the key is pressed
            state = true;
            break; // Stop here
           
        } else {
           
            // This means the key is released
        }
       
    }
   
    return state;
}


The game was stopped at "IOHIDDeviceRef device = IOHIDElementGetDevice(*it);" because "*it" was null.
I think this problem is caused by releasing elements in m_keys[] due to reconnection of keyboard or something else.

To identify what key is pressed, "HIDInputManager::isKeyPressed(Keyboard::Key key)" function is called several times. At every function calls, "value", returned from "IOHIDDeviceGetValue()" might be null and function releases "m_keys[]" as shown above code.

when the number of vector(m_keys[]) becomes zero, game crashes because there is no elements in the vector.

I need an advice to fix it. 

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: [OSX] keyboard problem (related: sf::isKeyPressed(Key key) )
« Reply #1 on: August 26, 2013, 08:12:44 pm »
Can you create a http://sscce.org/ reproducing the problem and open an issue on github ?
SFML / OS X developer

 

anything