Help with SDL Error Please!

Started by
5 comments, last by Helsing 19 years, 10 months ago
I know this is going to be very simple for someone but I cannot set the problem for myself. I can compile the code below and it compiles without errors or warningings, but when I run it I get the error: "Run-Time check failure #3 The variable event is being used without being defined" void CTWGame:lay() { int done=0; while(done == 0) { SDL_Event *event; while(SDL_PollEvent(event)) { if (event->type == SDL_QUIT) done =1; } DrawScene(); } } Any Ideas???
Advertisement
The way you''re using SDL_PollEvent is non kosher. Either pass it the address of a valid event structure, or pass it null. i.e.:

SDL_Event event;
while (SDL_PollEvent(&event)) {
SDL_Event *event;
while(SDL_PollEvent(event))

needs to be

SDL_Event event;
while(SDL_PollEvent(&event))
I have tried both of the above and now come back with errors at compile time. Perhaps I am being a bit retarded here.


I now get
"SDL_Event" does not have an overloaded member operator ->

left of''->type> must point to class/struct/union

I know I am missing something here.

You can use event.type instead of event->type.
Or, if you insist on using a pointer the whole time, you can leave it the way you had it before and change the beginning to
SDL_Event *event=new SDL_Event(); //I'm not positive about this                                  //syntax, I've being using Java                                  //recentlywhile(SDL_PollEvent(event))


Zorx (a Puzzle Bobble clone)
Discontinuity (an animation system for POV-Ray)

[edited by - clum on June 2, 2004 10:21:11 AM]
Zorx (a Puzzle Bobble clone)Discontinuity (an animation system for POV-Ray)
Thanks Clum

Thats sorted the problem.

I dont envy you with Java, I have never managed to get on with, but perhaps one day I will return to it.
quote:Original post by Helsing
I have tried both of the above and now come back with errors at compile time. Perhaps I am being a bit retarded here.


I now get
"SDL_Event" does not have an overloaded member operator ->

left of''->type> must point to class/struct/union

I know I am missing something here.



Check out what line you get that error at. When the object is a pointer, you use the -> operator, if not you use the . operator. Try changing event->type into event.type
2 + 2 = 5 for extremely large values of 2

This topic is closed to new replies.

Advertisement