[SDL] Bug in resizing window in win32 ?

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


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



More information about the SDL mailing list