Well, let’s do this… I’ll write every line that’s related to SDL. I
native language is Spanish so please don’t mind the names of the
functions and variables…
I have this prototype in my .h:
static int hiloEventos(void* param);
I’m calling it like this:
SDL_Thread* thread;
thread = SDL_CreateThread(hiloEventos, this);
Now, let’s go inside hiloEventos()…
…//Do some stuff that’s not related to the issue, and would take a lot
of time to understand, but that has nothing to do with SDL.
SDL_Event evento;
SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
SDL_EventState(SDL_JOYAXISMOTION, SDL_IGNORE);
SDL_EventState(SDL_JOYBALLMOTION, SDL_IGNORE);
SDL_EventState(SDL_JOYHATMOTION, SDL_IGNORE);
SDL_EventState(SDL_JOYBUTTONDOWN, SDL_IGNORE);
SDL_EventState(SDL_JOYBUTTONUP, SDL_IGNORE);
SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
SDL_EventState(SDL_VIDEORESIZE, SDL_IGNORE);
SDL_EventState(SDL_VIDEOEXPOSE, SDL_IGNORE);
SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
…//More stuff that doesn’t matter. And then the important part…
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
while(!player->exit){
tecla = 0;
while ( SDL_PollEvent(&evento) || (enviar) ){
if (player->mouse){
SDL_GetMouseState(&x,&y);
x += ( player->rect.x + player->verticeX);
y += ( player->rect.y + player->verticeY);
}
if (player->teclado) mod = SDL_GetModState();
switch(evento.type){
case SDL_MOUSEBUTTONDOWN:
switch(evento.button.button){
case SDL_BUTTON_LEFT:
click=1;
break;
case SDL_BUTTON_MIDDLE:
click=3;
break;
case SDL_BUTTON_RIGHT:
click=5;
break;
case SDL_BUTTON_WHEELDOWN:
click=7;
break;
default:
click=0;
break;
}
break;
case SDL_MOUSEBUTTONUP:
switch(evento.button.button){
case SDL_BUTTON_LEFT:
click=2;
break;
case SDL_BUTTON_MIDDLE:
click=4;
break;
case SDL_BUTTON_RIGHT:
click=6;
break;
case SDL_BUTTON_WHEELUP:
click=8;
break;
default:
click=0;
break;
}
break;
case SDL_KEYDOWN:
if ( (evento.key.keysym.mod & KMOD_CTRL) && (evento.key.keysym.mod &
KMOD_ALT) && (evento.key.keysym.sym == SDLK_F12) )
player->exit = true;
else if ( (player->teclado) && ( (evento.key.keysym.sym <
SDLK_NUMLOCK) || (evento.key.keysym.sym > SDLK_COMPOSE) ||
(evento.key.keysym.sym == SDLK_LSUPER) || (evento.key.keysym.sym ==
SDLK_RSUPER) || (evento.key.keysym.sym == SDLK_SCROLLOCK) ) )
tecla = player->mappearTecla(evento.key.keysym.sym);
break;
case SDL_QUIT:
player->exit = true;
break;
default:
click=0;
tecla=0;
break;
}
…//More irrelevant stuff. Then I close the while and return.
The line that’s executing many times, is:
tecla = player->mappearTecla(evento.key.keysym.sym);
It’s doing it as fast as it’s set by the enable key repeat.
Doug escribi?:> In article <466F5025.8090600 at yahoo.com.ar>, @Manuel_Garcia_Cabrer
says…
Let me explain what I’m doing. I’m doing a VNC client. I have two
threads, one that is constantly showing images that are received from
the net, and other that is constantly looking for mouse and keyboard
events (quit events too, of course). Well, I can show you the code in
the events thread, but I don’t see how it would help. If I put a printf
inside the case SDL_KEYDOWN it prints even when I released the key…
Your code may help. You’ve shown us only three lines of a sample switch
statement. Your problem could possibly be as simple as a missing break
statement on a case clause causing the execution to pass through into
another case clause unintentionally.
Also, what platform is this? Win32? Linux? Other?
Further, I don’t know all the ins and out of this issue, but there are
certain SDL things you simply cannot do in another thread. Certain SDL
functions must be called in and only in the main thread. I’m not sure if
there’s a list, but using some SDL functions in different threads can
cause issues as SDL is not 100% thread safe.
Doug.
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org