Having a issue with Events

I wrote this event

Code:

bool Running = true;
SDL_Event event;

while(Running)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
Running = false;
}
return Running;
}

Basicly all my window does is close out an returns -1 (note this is not the whole code) Any ideas why this wouldn’t wait for the user to want to [x] out of window?

I don’t think you want the ‘return Running’ line there. It would exit the
current function (not just the loop) every time you receive any event.

Jonny DOn Tue, Nov 17, 2009 at 6:42 PM, Tivoilos wrote:

I wrote this event

Code:

bool Running = true;
SDL_Event event;

while(Running)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
Running = false;
}
return Running;
}

Basicly all my window does is close out an returns -1 (note this is not the
whole code) Any ideas why this wouldn’t wait for the user to want to [x] out
of window?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

didn’t work

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Tivoilos wrote:

Basicly all my window does is close out an returns -1 (note this is not
the whole code) Any ideas why this wouldn’t wait for the user to want to
[x] out of window?

Are you initializing SDL properly? Are you checking SDL_Init’s return code? Can
you post the whole code? If you realign your code’scurly brackets, then it’s
only ever polls for one event and quits:

  • ----8<----
    bool Running = true;
    SDL_Event event;
    while(Running)
    {
    while(SDL_PollEvent(&event))
    {
    if(event.type == SDL_QUIT)
    {
    Running = false;
    }
    return Running;
    }
    }
  • ----8<----

Try the following instead:

  • ----8<----
    bool running = true;
    while (running)
    {
    SDL_Event e;
    int rc = SDL_PollEvent(&event);
    if (rc == 0)
    {
    printf(“Nothing to do\n”);
    }
    else if (rc == 1)
    {
    switch (event.type)
    {
    case SDL_QUIT:
    printf(“Received SDL_QUIT\n”);
    running = false;
    break;
    default:
    printf(“Received something other than SDL_QUIT\n”);
    break;
    }
    }
    }
    return running;
  • ----8<----

Then look at the output and go from there.

CE
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEAREKAAYFAksDWZUACgkQwCnbyd7dCqQZMQCgiqT8QC0Lw4veP0u+1hM0t9HH
PvQAoLGizJWE+QP/dVn3G/6CA8+uonco
=LDYo
-----END PGP SIGNATURE-----

I wrote this event

Code:

bool Running = true;
SDL_Event event;

while(Running)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
Running = false;
}
return Running;
}

Basicly all my window does is close out an returns -1 (note this is not the
whole code) Any ideas why this wouldn’t wait for the user to want to [x] out
of window?

I don’t know what other problems the code may have, but you must remove
"return Running". As soon as there is a single event in the queue, this code
will return true or false but it will not process all the events in the
queue. What you want, is to change “break;” right after "Running = false;“
If you make both of those changes then your code will stay in a loop looking
for a quit event until you find one. Then it will set Running to false, and
"break” out of the inner while loop. That will let the outer while loop exit
(because Running will now be false.

Bob PendletonOn Tue, Nov 17, 2009 at 5:42 PM, Tivoilos wrote:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------