Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: OIS Mac gotcha: Don't call keyboard capture() from a key event handler  (Read 797 times)

ivucica

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 5
    • View Profile

Calling keyboard's capture() from within a keyboard event handler makes Jack a very sad boy on Mac. This can easily happen with Ogre3d, where it appears typical to put keyboard capture() within frameStarted(). Triggering is as easy as calling Ogre's renderOneFrame(). On Windows, this bug didn't crash (and I didn't check out the code to see why).

Apparently the mess happens when OIS tries to dereference an iterator in the "parent" call to capture() once that resumes. However this iterator was already cleared from the pendingEvents map/vector/whatever in the "child" call to capture() -- in the one caused by, e.g., renderOneFrame(). 

Perhaps a check variable should be added, some sort of a lock mechanism: if we're already within capture() function, then let's do a 'return' immediately at the top?

practical sample:
* user presses enter on "Load" menu
* parsing keypress events starts in capture()
* function for loading next level is called. renderOneFrame() is used to display the loading screen, but nothing else
* renderOneFrame() calls frameStarted() which calls capture(); after parsing events, clear() is called
* loading proceeds
* loading finishes, parsing keypress events in capture() attempts to resume, but crashes since clear was called and dereferencing, incrementing, etc. of the iterator must fail

(This bug was encountered with PythonOgre, but I see no reason for it to be specific to the language and the wrapper; it seems like perfectly easy to trigger by coding in C++.)
Logged

ivucica

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 5
    • View Profile
Re: OIS Mac gotcha: Don't call keyboard capture() from a key event handler
« Reply #1 on: October 26, 2009, 03:58:32 AM »

Oh, I am not ordinarily following these forums, so please PM me if you reply, so that an email is dropped in my inbox. Thanks.
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2652
    • View Profile
    • http://www.wreckedgames.com
Re: OIS Mac gotcha: Don't call keyboard capture() from a key event handler
« Reply #2 on: October 26, 2009, 07:35:42 AM »

Sorry, don't have time to PM.

I'm not quite sure I see the issue this early in the morning. Though, the Mac code is less than optimal, as the event triggers could technically end up firing input messages from a different thread and outside of the user calling capture. It should, really, buffer the incoming messages, and only fire them from the capture method itself, and not from the OSX event callbacks.
Logged

ivucica

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 5
    • View Profile
Re: OIS Mac gotcha: Don't call keyboard capture() from a key event handler
« Reply #3 on: December 17, 2009, 08:39:00 AM »

Just wondering, have you reexamined this later? Do you want me to try and produce some demo code? (May take a while, but I could try to do something).
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2652
    • View Profile
    • http://www.wreckedgames.com
Re: OIS Mac gotcha: Don't call keyboard capture() from a key event handler
« Reply #4 on: December 19, 2009, 07:53:26 AM »

Something that shows the problem would be useful. Or a patch that works around the issue.
Logged