Not Response on Window Mode (on WindowsXP)

Hello all, I’m newbie here and I have some problem.

First, I google and found this message :-
http://www.devolution.com/pipermail/sdl/2003-July/055521.html

It show the same problem that i faced, but no solution there.

My problem is , in Window Mode, application seems like it does not
response to mouse event (it does not generate mouse event when mouse is
clicked) even if
SDL_WM_GrabInput is called. And also , after some click or draging the
title bar, the window become white and “Not Responding” is shown on
title (but it is still draw and get input from keyboard).

This problem is not found on Full-Screen Mode.

Here is the rendering code :-

int UpdateScreen(void* data)
{
static long exframe = SDL_GetTicks();
while(true)
{
//Delay each frame for approx 33ms
//SDL_Delay(33);

    //Start Render new Frame
    SDL_LockMutex(mutex);
    long now = SDL_GetTicks();

    if(now-exframe >=33)
    {
        exframe = now;

        //Clear Frame Buffer
        SDL_FillRect(backBuffer,NULL,0xffffffff);
        //Draw Text to Screen
        SDL_BlitSurface(background,NULL,backBuffer,NULL);
        box->Draw(backBuffer);
        SDL_BlitSurface(messageBuffer,NULL,backBuffer,NULL);
    }
    //Do Event
    SDL_Event event;
    while(SDL_PollEvent(&event)==1)
    {
        box->ActionPerformed(event);
    };
    //Flip Frame Buffer
    SDL_Flip(backBuffer);
    SDL_UnlockMutex(mutex);
    //Finish Render Frame
}
return 0;

}

working on the separated Thread.

Using SDL 1.2.9 with SDL_TTF and SDL_image, GCC 3.4.2 (MINGW), WindowsXP
Pro SP2 and DirectX9.0c.

This problem is not found on Full-Screen Mode.

You are doing SDL_Flip() a lot, even when nothing has changed
and it hasn’t been “33” ms. (e.g., if there were no events, it still
SDL_Flip()'s, which might be expensive, esp. in windowed / software surface
modes.)

Try only SDL_Flip()'ing when you actually do the SDL_BlitSurface() stuff.

-bill!

Here is the rendering code :-

int UpdateScreen(void* data)
{
static long exframe = SDL_GetTicks();
while(true)
{
//Delay each frame for approx 33ms
//SDL_Delay(33);

   //Start Render new Frame
   SDL_LockMutex(mutex);
   long now = SDL_GetTicks();

   if(now-exframe >=33)
   {
       exframe = now;

       //Clear Frame Buffer
       SDL_FillRect(backBuffer,NULL,0xffffffff);
       //Draw Text to Screen
       SDL_BlitSurface(background,NULL,backBuffer,NULL);
       box->Draw(backBuffer);
       SDL_BlitSurface(messageBuffer,NULL,backBuffer,NULL);
   }
   //Do Event
   SDL_Event event;
   while(SDL_PollEvent(&event)==1)
   {
       box->ActionPerformed(event);
   };
   //Flip Frame Buffer
   SDL_Flip(backBuffer);
   SDL_UnlockMutex(mutex);
   //Finish Render Frame

}
return 0;
}

-bill!On Sat, Nov 12, 2005 at 03:18:43AM +0700, Wutipong Wongsakuldej wrote:

Bill Kendrick wrote:

This problem is not found on Full-Screen Mode.

You are doing SDL_Flip() a lot, even when nothing has changed
and it hasn’t been “33” ms. (e.g., if there were no events, it still
SDL_Flip()'s, which might be expensive, esp. in windowed / software surface
modes.)

Try only SDL_Flip()'ing when you actually do the SDL_BlitSurface() stuff.

-bill!

I’ve tried to use SDL_Delay() , but still same result :frowning:
Anyway, thanks so much for suggestion.> On Sat, Nov 12, 2005 at 03:18:43AM +0700, Wutipong Wongsakuldej wrote:

Here is the rendering code :-

int UpdateScreen(void* data)
{
static long exframe = SDL_GetTicks();
while(true)
{
//Delay each frame for approx 33ms
//SDL_Delay(33);

   //Start Render new Frame
   SDL_LockMutex(mutex);
   long now = SDL_GetTicks();

   if(now-exframe >=33)
   {
       exframe = now;

       //Clear Frame Buffer
       SDL_FillRect(backBuffer,NULL,0xffffffff);
       //Draw Text to Screen
       SDL_BlitSurface(background,NULL,backBuffer,NULL);
       box->Draw(backBuffer);
       SDL_BlitSurface(messageBuffer,NULL,backBuffer,NULL);
   }
   //Do Event
   SDL_Event event;
   while(SDL_PollEvent(&event)==1)
   {
       box->ActionPerformed(event);
   };
   //Flip Frame Buffer
   SDL_Flip(backBuffer);
   SDL_UnlockMutex(mutex);
   //Finish Render Frame

}
return 0;
}

-bill!


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Bill Kendrick wrote:

This problem is not found on Full-Screen Mode.

You are doing SDL_Flip() a lot, even when nothing has changed
and it hasn’t been “33” ms. (e.g., if there were no events, it still
SDL_Flip()'s, which might be expensive, esp. in windowed / software surface
modes.)

Try only SDL_Flip()'ing when you actually do the SDL_BlitSurface() stuff.

-bill!

I’ve changed to this :-

int UpdateScreen(void* data)
{
static long exframe = SDL_GetTicks();
while(true)
{
//Delay each frame for approx 33ms
//SDL_Delay(33);

    //Start Render new Frame
    SDL_LockMutex(mutex);
    long now = SDL_GetTicks();

    if(now-exframe >=33)
    {
        exframe = now;

        //Clear Frame Buffer
        SDL_FillRect(backBuffer,NULL,0xffffffff);
        //Draw Text to Screen
        SDL_BlitSurface(background,NULL,backBuffer,NULL);
        box->Draw(backBuffer);
        SDL_BlitSurface(messageBuffer,NULL,backBuffer,NULL);
        //Flip Frame Buffer
        SDL_Flip(backBuffer);
        //Do Event
        SDL_Event event;
        while(SDL_PollEvent(&event)==1)
        {
            box->ActionPerformed(event);
        };
    }
    SDL_UnlockMutex(mutex);
    //Finish Render Frame
    SDL_Delay(0);
}
return 0;

}

And the result is still the same (I mean, window is not movable, and
become not respond).> On Sat, Nov 12, 2005 at 03:18:43AM +0700, Wutipong Wongsakuldej wrote:

Here is the rendering code :-

-bill!


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

[snip]

And the result is still the same (I mean, window is not movable, and
become not respond).

Remember to call SDL_PumpEvents() before you start polling. Otherwise
no events are going to reach your polling loop…–
Rasmus Neckelmann

“Often the need for calls to SDL_PumpEvents is hidden from the user
since SDL_PollEvent and SDL_WaitEvent implicitly call SDL_PumpEvents.
However, if you are not polling or waiting for events (e.g. you are
filtering them), then you must call SDL_PumpEvents to force an event
queue update.”

from the wiki.On 11/12/05, Rasmus Neckelmann wrote:

[snip]

And the result is still the same (I mean, window is not movable, and
become not respond).

Remember to call SDL_PumpEvents() before you start polling. Otherwise
no events are going to reach your polling loop…


Rasmus Neckelmann


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Okay then, is there any example/demo that is working on window mode on
1.2.9 ?
And also,is there anywhere can i get the old-version of SDL runtime for
Widows?

I will try to build SDL runtime myself and see if it working.

Brian Barrett wrote:> "Often the need for calls to SDL_PumpEvents is hidden from the user

since SDL_PollEvent and SDL_WaitEvent implicitly call SDL_PumpEvents.
However, if you are not polling or waiting for events (e.g. you are
filtering them), then you must call SDL_PumpEvents to force an event
queue update."

from the wiki.

On 11/12/05, Rasmus Neckelmann wrote:

[snip]

And the result is still the same (I mean, window is not movable, and
become not respond).

Remember to call SDL_PumpEvents() before you start polling. Otherwise
no events are going to reach your polling loop…


Rasmus Neckelmann


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

[…]On Saturday 12 November 2005 15.51, Wutipong Wongsakuldej wrote:

I’ve changed to this :-

int UpdateScreen(void* data)
{
static long exframe = SDL_GetTicks();
while(true)
{
//Delay each frame for approx 33ms
//SDL_Delay(33);

    //Start Render new Frame

    SDL_LockMutex(mutex);

What’s this mutex about? You’re not by any chance trying to lock it
(indirectly) from inside the ActionPerformed() method you’re passing
events to…?

    long now = SDL_GetTicks();

    if(now-exframe >=33)
    {
        exframe = now;

        //Clear Frame Buffer
        SDL_FillRect(backBuffer,NULL,0xffffffff);
        //Draw Text to Screen
        SDL_BlitSurface(background,NULL,backBuffer,NULL);
        box->Draw(backBuffer);
        SDL_BlitSurface(messageBuffer,NULL,backBuffer,NULL);
        //Flip Frame Buffer
        SDL_Flip(backBuffer);
        //Do Event
        SDL_Event event;
        while(SDL_PollEvent(&event)==1)
        {
            box->ActionPerformed(event);
        };
    }
    SDL_UnlockMutex(mutex);
    //Finish Render Frame

    SDL_Delay(0);

Note that this SDL_Delay(0) will only work on Windows. There, it’s
equivalent to Unx sched_yield() (give up the CPU to other runable
threads, if any) - but on Un
x (POSIX API), it has no effect
whatsoever.

Also note that unless you’re using a driver that’s (IMHO) broken or
misconfigured to ignore retrace sync, you should not add any delays
like this. SDL_Flip() is where the rendering thread should go to
sleep, waiting for the driver to let go of the back buffer - but
unfortunately, you have to deal with the case where this does not
happen. I strongly recommend implementing a user configurable frame
rate throttling feature.

[…]

And the result is still the same (I mean, window is not movable, and
become not respond).

That’s the exact symptoms of ignoring Win32 messages, so it does
indeed seem like SDL_PollEvent() isn’t getting called regularly, if
at all.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se

[…]


    SDL_Delay(0);

Note that this SDL_Delay(0) will only work on Windows. There, it’s
equivalent to Unx sched_yield() (give up the CPU to other runable
threads, if any) - but on Un
x (POSIX API), it has no effect
whatsoever.

Correction:

It seems that, at least in the SDL 1.2.9 tree I’m looking at now, this
has been fixed, and SDL_Delay() indeed will yield on Linux even if
you pass 0.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Saturday 12 November 2005 20.16, David Olofson wrote:

David Olofson wrote:
[snip]

[…]

And the result is still the same (I mean, window is not movable, and
become not respond).

That’s the exact symptoms of ignoring Win32 messages, so it does
indeed seem like SDL_PollEvent() isn’t getting called regularly, if
at all.

I’ve switched to Microsoft Visual Studio.Net 2003 to see if it better.
And yes it is better, no “Not Responding” anymore, but still cannot take
any mouse event.
It works fine in Full Screen mode.

I think because in Full Screen mode, all input is managed by
DirectInput, and it is not when in Window Mode (There’s comment state
that in ./src/video/wincommon/SDL_sysevents.c). Maybe I might check that
is it possible to use DirectInput all the time.

Also it seems like VS.Net03 does not recognize the source code that it
is UTF-8, so I have to convert some source file to UTF-8 encoding.

I will managed to test the code on Linux platform as soon as I get the CD.> //David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

[…]

My problem is , in Window Mode, application seems like it does not
response to mouse event (it does not generate mouse event when mouse is
clicked) even if
SDL_WM_GrabInput is called. And also , after some click or draging the
title bar, the window become white and “Not Responding” is shown on
title (but it is still draw and get input from keyboard).

This problem is not found on Full-Screen Mode.

Here is the rendering code :-

int UpdateScreen(void* data)
{
[… graphics code snipped…]
return 0;
}

working on the separated Thread.

Please keep in mind that
a) SDL is not thread safe
b) You shouldn’t do any rendering outside the main thread
(this is not portable).

Johannes Schmidt

< http://libufo.sourceforge.net > The OpenGL GUI ToolkitAm Freitag 11 November 2005 21:18 schrieb Wutipong Wongsakuldej:

Johannes Schmidt wrote:

[snip]
Please keep in mind that
a) SDL is not thread safe
b) You shouldn’t do any rendering outside the main thread
(this is not portable).

I have done as your advise (move rendering process to main thread), and
now it works.

Thank you so much (also to the other that keep reply me)> Johannes Schmidt

< http://libufo.sourceforge.net > The OpenGL GUI Toolkit


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl