[SDL] Bug in resizing window in win32 ?

liam mail liam.list at googlemail.com
Fri Sep 19 07:35:51 PDT 2008


2008/9/19 Paolo Minazzi <paolo.minazzi at gmail.com>:
> I'm using SDL 1.2.13 on single core.
> Are you sure that my example program works ?
> Try continue minimize/maximize .... you have to do it several
> times....have a little patience...
>
> On my colinux-console I have tried to insert
> EnterCriticalSection/LeaveCriticalSection in the WM_PAINT win32
> message.
> I have not tried do it with this simple example.
>
> What I mean is that there is some race condition problem.
> When one call SDL_SetVideoMode resizing, ALL drawing stuff must be
> stopped until the resizing is done.
>
> Regards
> Paolo
>
>
> On Fri, Sep 19, 2008 at 4:07 PM, liam mail <liam.list at googlemail.com> wrote:
>> 2008/9/19 Peter Mackay <mackay.pete+sdl at gmail.com>:
>>> Hi,
>>>
>>> One thing I would check first is whether SDL_Flip is allowed to be
>>> called outside the main thread.
>>>
>>> My code is largely single threaded so I have no idea which functions
>>> are or aren't thread-safe through design or implementation details.
>>>
>>> What you might want to do is set up an event or condition variable to
>>> signal that a flip should be done. Set this from your drawing thread,
>>> wait for it in the main thread and do the flip there.
>>>
>>> Of course if you try that, you may want to stop you drawing thread
>>> from drawing during the call to SDL_Flip.
>>>
>>> Peter
>>>
>>> 2008/9/19 Paolo Minazzi <paolo.minazzi at gmail.com>:
>>>> Hi,
>>>> in this case SDL_GetError cannot give us information.
>>>> The application does not respond of enter in a fault.
>>>>
>>>> I think
>>>> 1) there are race condition in SDL-library in resizing OR
>>>> 2) I use badly SDL-library
>>>>
>>>> I understand my example is a very strange program, but if I change
>>>> fonts in my new colinux console I have exactly this problem.
>>>>
>>>> Regards,
>>>> Paolo
>>>>
>>>>
>>>> On Fri, Sep 19, 2008 at 3:18 PM, liam mail <liam.list at googlemail.com> wrote:
>>>>> 2008/9/19 Paolo Minazzi <paolo.minazzi at gmail.com>:
>>>>>> Hi people,
>>>>>> I'm developing an SDL console for colinux.
>>>>>> I have used the SDL library under win32.
>>>>>>
>>>>>> The following program show well the problem I have encoutered.
>>>>>>
>>>>>> There is :
>>>>>>
>>>>>> main
>>>>>> - change window size
>>>>>> - check events
>>>>>>
>>>>>> drawing thread
>>>>>> - contine to update window
>>>>>>
>>>>>> I have used EnterCriticalSection and LeaveCriticalSection to avoid
>>>>>> race condition problem.
>>>>>>
>>>>>> To see the problem run it and try some times to minimize and maximize.
>>>>>> After some proofs you will see that application does not respond anymore.
>>>>>>
>>>>>> Any ideas ?
>>>>>> Do I make some error ?
>>>>>>
>>>>>> Thanks
>>>>>> Paolo
>>>>>>
>>>>>> ********************************************************************************
>>>>>>
>>>>>> #include <stdio.h>
>>>>>> #include <SDL.h>
>>>>>> #include <windows.h>
>>>>>>
>>>>>> #define WIDTH 640
>>>>>> #define HEIGHT 20
>>>>>> #define BPP 4
>>>>>> #define DEPTH 32
>>>>>>
>>>>>> SDL_Surface *screen;
>>>>>> CRITICAL_SECTION crit;
>>>>>> unsigned char K=0;
>>>>>>
>>>>>> void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
>>>>>> {
>>>>>>    Uint32 *pixmem32;
>>>>>>    Uint32 colour;
>>>>>>    colour = SDL_MapRGB( screen->format, r, g, b );
>>>>>>    pixmem32 = (Uint32*) screen->pixels  + y + x;
>>>>>>    *pixmem32 = colour;
>>>>>> }
>>>>>>
>>>>>> void DrawScreen(SDL_Surface* screen, int h)
>>>>>> {
>>>>>>    int x, y, ytimesw;
>>>>>>    for(y = 0; y < screen->h; y++ )
>>>>>>    {
>>>>>>        ytimesw = y*screen->pitch/BPP;
>>>>>>        for( x = 0; x < screen->w; x++ )
>>>>>>        {
>>>>>>            setpixel(screen, x, ytimesw, (x*x)/256+3*y+h, (y*y)/256+x+h, h);
>>>>>>        }
>>>>>>    }
>>>>>>    SDL_Flip(screen);
>>>>>> }
>>>>>>
>>>>>>
>>>>>> void drawing_thread(void *p)
>>>>>> {
>>>>>>    static int h=0;
>>>>>>    while(1)
>>>>>>    {
>>>>>>        EnterCriticalSection(&crit);
>>>>>>        DrawScreen(screen,h++);
>>>>>>        LeaveCriticalSection(&crit);
>>>>>>    }
>>>>>> }
>>>>>>
>>>>>> void Change_Window_Size()
>>>>>> {
>>>>>>        EnterCriticalSection(&crit);
>>>>>>        if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT+K, DEPTH, 0 )))
>>>>>>    {
>>>>>>        SDL_Quit();
>>>>>>                printf("ERRORE\n");
>>>>>>        fflush(stdout);
>>>>>>        return;
>>>>>>    }
>>>>>>    LeaveCriticalSection(&crit);
>>>>>> }
>>>>>>
>>>>>> int main(int argc, char* argv[])
>>>>>> {
>>>>>>    SDL_Event event;
>>>>>>
>>>>>>    int keypress = 0;
>>>>>>
>>>>>>        InitializeCriticalSection(&crit);
>>>>>>
>>>>>>    if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
>>>>>>
>>>>>>    if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, 0 )))
>>>>>>    {
>>>>>>        SDL_Quit();
>>>>>>                printf("ERRORE\n");
>>>>>>        fflush(stdout);
>>>>>>        return 1;
>>>>>>    }
>>>>>>
>>>>>>    _beginthread(drawing_thread,0,0);
>>>>>>
>>>>>>    K=0;
>>>>>>
>>>>>>    while(!keypress)
>>>>>>    {
>>>>>>
>>>>>>                K++;
>>>>>>
>>>>>>                if ( (K % 8) == 0 )
>>>>>>                {
>>>>>>                        Change_Window_Size();
>>>>>>                }
>>>>>>
>>>>>>                // Sleep(10);
>>>>>>
>>>>>>                while(SDL_PollEvent(&event))
>>>>>>        {
>>>>>>              switch (event.type)
>>>>>>              {
>>>>>>                  case SDL_QUIT:
>>>>>>                                keypress = 1;
>>>>>>                                break;
>>>>>>                  case SDL_KEYDOWN:
>>>>>>                                keypress = 1;
>>>>>>                        break;
>>>>>>              }
>>>>>>        }
>>>>>>    }
>>>>>>
>>>>>>    SDL_Quit();
>>>>>>
>>>>>>    return 0;
>>>>>> }
>>>>>> _______________________________________________
>>>>>> SDL mailing list
>>>>>> SDL at lists.libsdl.org
>>>>>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>>>>>
>>>>>
>>>>> Calling SDL_GetError will give you the information about the problem.
>>>>> _______________________________________________
>>>>> SDL mailing list
>>>>> SDL at lists.libsdl.org
>>>>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>>>>
>>>> _______________________________________________
>>>> SDL mailing list
>>>> SDL at lists.libsdl.org
>>>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>>>
>>> _______________________________________________
>>> SDL mailing list
>>> SDL at lists.libsdl.org
>>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>>
>> Which version of SDL are you using and does you pc have more than one core?
>> On a single core machine running 1.2.12 I have no problem
>> _______________________________________________
>> SDL mailing list
>> SDL at lists.libsdl.org
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
"Are you sure that my example program works ?"
Yes quite sure
"Try continue minimize/maximize .... you have to do it several
times....have a little patience..."
You mean minimise and restore?



More information about the SDL mailing list