SDL_PollEvent dropping keyboard events

I’m running a standard SDL_PollEvent loop once per frame. Most events seem to work fine, but keyboard input is unreliable. Not just a little flaky here and there, but “hello world” becomes “elowrd”, and so on. I’m simply not getting key down (or text input) events for a large percentage of keypresses.

I’m using SDL 2 on MacOS X 10.8.4. The underlying engine (using Ogre) is running at 60fps, meaning the SDL_PollEvent loop is too. The only oddity I can think of is that I used SDL_CreateWindowFrom(ogreWindow), and not SDL_CreateWindow. But again, everything else about this setup seems fine.

I know SDL_GetKeyboardState() is preferable for game control, but in this situation I need text input; events seem like the way to go for that. But this is totally unusable - even slow, deliberate typing drops characters constantly. Any suggestions for making keyboard events work properly?

You are using the standard render loop of Ogre (i.e. Root::startRendering)?
I’ve come across a similiar problem, it was caused by Ogre’s
WindowEventUtilities::messagePump occassionally stealing some events.
You can work around it by not using Root::startRendering which is
calling this method.
Instead, try this:

while (!shutdown) root->renderOneFrame()

It only happens on Mac, and the other platforms do need
WindowEventUtilities::messagePump to function properly.
Take a look at the workaround we’re using:


Note that we are using SDL_CreateWindow, not SDL_CreateWindowFrom (we’ve
found the latter to not work well enough on windows).On 27.06.2013 16:14, xtapol wrote:

I’m running a standard SDL_PollEvent loop once per frame. Most events
seem to work fine, but keyboard input is unreliable. Not just a little
flaky here and there, but “hello world” becomes “elowrd”, and so on.
I’m simply not getting key down (or text input) events for a large
percentage of keypresses.

I’m using SDL 2 on MacOS X 10.8.4. The underlying engine (using Ogre)
is running at 60fps, meaning the SDL_PollEvent loop is too. The only
oddity I can think of is that I used SDL_CreateWindowFrom(ogreWindow),
and not SDL_CreateWindow. But again, everything else about this setup
seems fine.

I know SDL_GetKeyboardState() is preferable for game control, but in
this situation I need text input; events seem like the way to go for
that. But this is totally unusable - even slow, deliberate typing
drops characters constantly. Any suggestions for making keyboard
events work properly?

scrawl wrote:

You are using the standard render loop of Ogre (i.e. Root::startRendering)?
I’ve come across a similiar problem, it was caused by Ogre’s
WindowEventUtilities::messagePump occassionally stealing some events.
You can work around it by not using Root::startRendering which is
calling this method.

No, the standard render loop has problems with Cocoa. I’m already doing it manually, like so:

Code:
// Run one iteration of the render loop
void renderer::loop_once()
{
_window->update(false);
_window->swapBuffers(true);

	_root->renderOneFrame();
	Ogre::WindowEventUtilities::messagePump();
}

Based on your suggestion, I tried removing the call to messagePump, but it didn’t seem to make any difference. Same behavior.

scrawl wrote:

Take a look at the workaround we’re using:
https://github.com/zinnschlag/openmw/blob/master/libs/openengine/ogre/renderer.cpp#L69

This, however, put me on the right track. I was calling loop_once() from an NSTimer callback, because that was the only way events seemed to work at all. Ogre::WindowUtils::messagePump was the culprit in that case, and now after removing that, calling loop_once() repeatedly in an infinite loop works great.

Thanks for your help!