tags:

views:

34

answers:

1

I have a general function that is supposed to handle any event in the SDL event queue. So far, the function looks like this:

int eventhandler(void* args){
  cout << "Eventhandler started.\n";
  while (!quit){
    while (SDL_PollEvent(&event)){
      cout << "Got event to handle: " << event.type << "\n";
      switch (event.type){
        SDL_KEYDOWN:
          keyDownHandler(event.key.keysym.sym);
          break;
        default:
          break;
      }
    }
  }
}

However, when I test the function, I get a whole bunch of events but none of them seem to have a type. It doesn't even print 0 or anything — just nothing. The output when pressing any key looks like this:

Got event to handle:

And nothing else. Any tutorial and the SDL docs say that I should handle events like this, but it isn't working. Anybody else have this problem or a solution?

By the way, the eventhandler runs in an SDL_Thread, but I don't think that's the problem.

+1  A: 

That nothing happens is a result of the missing case in front of SDL_KEYDOWN.
With case missing the compiler sees a jump label which you would use for e.g. goto SDL_KEYDOWN;, which results in the default label being the only label in the switch statement.

I don't see why event.type doesn't get output though unless you set some stream-flags somewhere.
event.type is an Uint8 which SDL just typedefs from integral types, so it should be handled like one. Like any integral type it also can't be "empty", but the output for it can be.

Georg Fritzsche