Sign in to follow this  
rcarvajal

SDL_PollEvents going CRAZY

Recommended Posts

rcarvajal    122
In a normal while loop for processing events a specific structure gets trashed. Can anyone explain why this could be happening: -------------------------- #include <SDL/SDL.h> #include <GL/gl.h> #include <GL/glu.h> #include <stdlib.h> #include <stdio.h> struct particle { float x, vx; float y, vy; }; int main() { SDL_Event event; int done=0; struct particle falling_obj[2]; falling_obj[0].x=falling_obj[0].vx=0.0f; falling_obj[0].y=10.0f; falling_obj[0].vy=-98.0f; falling_obj[1].x=falling_obj[1].vx=0.0f; falling_obj[1].y=10.0f; falling_obj[1].vy=-98.0f; SDL_Init(SDL_INIT_VIDEO); SDL_SetVideoMode(800,600,24,SW_SURFACE | SW_FULLSCREEN | SW_OPENGL); setup_opengl(); // Just the usual stuff... while(!done) { fprintf(stderr, "y:%f vy:%f\n", falling_obj[1].y, falling_obj[1].vy); while(SDL_PollEvents(&event)) { if(event.type==SDL_KEYDOWN) { switch(event.key.keysym.sym) { case SDL_ESCAPE: fprintf(stderr, "ESC!\n\n"); done=1; break; } } } fprintf(stderr, "y:%f vy:%f\n", falling_obj[1].y, falling_obj[1].vy); integrate(falling_obj); } SDL_Quit(); } --------------------------- Prints: y:10.000000 vy:-98.000000 y:0.000000 vy:0.000000 y:0.000000 vy:0.000000 y:0.000000 vy:0.000000 ... y:0.000000 vy:0.000000 ESC! --------------------------- Looks like in the while loop of the function SDL_PollEvent the variable gets trashed, i can say so because i comment that and the program acts normally (But obviously i can't interact nor exit the program). The integrate function takes the pointer to the structure's array and iterate over them taking a delta in time adding constant velocity. But the vars get lost before that happens. And actually if i print the first structure (falling_obj[0]) everything is ok. The problem seems to be only with the second structure. My system is FreeBSD 7 running on a Intel Xeon 2.2 Dual CPU and the SDL program running over Xorg. Any help is appreciated. [Edited by - rcarvajal on October 22, 2008 3:06:46 PM]

Share this post


Link to post
Share on other sites
evillive2    779
Probably not what you are looking for but...

Quote:
int main()
I don't know how this is even compiling without at least a warning considering sdlmain should complain.
Quote:
SDL_SetVideoMode(800,600,24,SW_SURFACE | SW_FULLSCREEN | SW_OPENGL);
Not sure where you got SW_FULLSCREEN and SW_OPENGL but I don't think they actually exist (in the SDL documentation anyway).
Quote:
setup_opengl(); // Just the usual stuff...
Considering the above it may be helpful to see this.
Quote:
integrate(falling_obj);
The error you are looking for is probably in here since you don't actually do anything with SDL_PollEvents relating to falling_obj.

Maybe it is just me but it doesn't appear that you posted the actual code you are working with. If you only post pieces of the problem assuming we will understand what you mean it will be very difficult for anyone to help you.

Tip - use the [ source ][ /source ] tags (sans spaces) to post formatted code to make it easier for people to read. More people may reply.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this