Bug in resizing window in win32?

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 = yscreen->pitch/BPP;
for( x = 0; x < screen->w; x++ )
{
setpixel(screen, x, ytimesw, (x
x)/256+3y+h, (yy)/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;

}

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 = yscreen->pitch/BPP;
for( x = 0; x < screen->w; x++ )
{
setpixel(screen, x, ytimesw, (x
x)/256+3y+h, (yy)/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.

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,
PaoloOn Fri, Sep 19, 2008 at 3:18 PM, liam mail <liam.list at googlemail.com> wrote:

2008/9/19 Paolo Minazzi <@Paolo_Minazzi>:

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 = yscreen->pitch/BPP;
for( x = 0; x < screen->w; x++ )
{
setpixel(screen, x, ytimesw, (x
x)/256+3y+h, (yy)/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

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 = yscreen->pitch/BPP;
for( x = 0; x < screen->w; x++ )
{
setpixel(screen, x, ytimesw, (x
x)/256+3y+h, (yy)/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

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

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 = yscreen->pitch/BPP;
for( x = 0; x < screen->w; x++ )
{
setpixel(screen, x, ytimesw, (x
x)/256+3y+h, (yy)/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>> On Fri, Sep 19, 2008 at 3:18 PM, liam mail <@liam_mail> wrote:

In my code all the drawing thread and so also the FLIP are protected
with EnterCriticalSection/LeaveCriticalSection.

I have done what you say !

I have protected

  • drawing thread
  • resizing window thread

with a mutex (EnterCriticalSection/LeaveCriticalSection).

Please see the following extract of my code …

I have tried the same vesion without the drawing thread (inserting the
drawing thread in the main) and all is OK.

Regards
Paolo>>>> 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);
}

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
PaoloOn 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>:

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>:

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 = yscreen->pitch/BPP;
for( x = 0; x < screen->w; x++ )
{
setpixel(screen, x, ytimesw, (x
x)/256+3y+h, (yy)/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

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

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

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 = yscreen->pitch/BPP;
for( x = 0; x < screen->w; x++ )
{
setpixel(screen, x, ytimesw, (x
x)/256+3y+h, (yy)/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?> On Fri, Sep 19, 2008 at 4:07 PM, liam mail <@liam_mail> wrote:

On Fri, Sep 19, 2008 at 3:18 PM, liam mail <@liam_mail> wrote:

minimize(reducing to icon) and maximize(enlarge the window, restoring it).

I compiled all with mingw32.

PaoloOn Fri, Sep 19, 2008 at 4:35 PM, liam mail <liam.list at googlemail.com> wrote:

2008/9/19 Paolo Minazzi <@Paolo_Minazzi>:

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>:

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>:

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 = yscreen->pitch/BPP;
for( x = 0; x < screen->w; x++ )
{
setpixel(screen, x, ytimesw, (x
x)/256+3y+h, (yy)/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?


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

Liam, thanks for your interest.
I have studied my problem and I realize that resizing SDL window has
to be done when SDL_Poll is not running. This solve one problem.
The other problem occour when pass from iconify-window to "normal
window) (on the screen).
If during this step I change resolution (this is my test) I have problem.
I understand that this is a very very very strange case and noone use it.
I was doing this test to verify some race condition problem.
Thanks for you interest.
Bye
PaoloOn Fri, Sep 19, 2008 at 4:38 PM, Paolo Minazzi <@Paolo_Minazzi> wrote:

minimize(reducing to icon) and maximize(enlarge the window, restoring it).

I compiled all with mingw32.

Paolo

On Fri, Sep 19, 2008 at 4:35 PM, liam mail <liam.list at googlemail.com> wrote:

2008/9/19 Paolo Minazzi <@Paolo_Minazzi>:

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>:

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>:

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 = yscreen->pitch/BPP;
for( x = 0; x < screen->w; x++ )
{
setpixel(screen, x, ytimesw, (x
x)/256+3y+h, (yy)/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?


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

Liam, thanks for your interest.
I have studied my problem and I realize that resizing SDL window has
to be done when SDL_Poll is not running. This solve one problem.
The other problem occour when pass from iconify-window to "normal
window) (on the screen).
If during this step I change resolution (this is my test) I have problem.
I understand that this is a very very very strange case and noone use it.
I was doing this test to verify some race condition problem.

The fact is that SDL video API calls should be performed on the main thread,
the fact it may work if something else doesn’t occur it may be true on
windows but not on other archs or with other versions of SDL, I suggest you
to build a SDL userevent in your thread and let the main thread perform the
Flip call in his loop.

Also be sure to use software surfaces, otherwise in HW surfaces “pixels” can
be null if surface is not locked, and you cannot lock a surface if you are
not the video thread owner…On Mon, Sep 22, 2008 at 8:27 AM, Paolo Minazzi <paolo.minazzi at gmail.com>wrote:


Bye,
Gabry

Hi Gabriele,
after a lot of proofs I realize that it is possible resizing a window
while is running GetMessage() function.
I agree with you that if someone wants avoid problems, the best way is
to put the critic code in the main thread.

But in some situation, when the programmer requires a very high
responsive application, this is not enough. In this case we need
multi-thread application. And for what I have tried, SDL on WIN32 give
us the possibility to WaitEvent, Resizing, Drawing in DIFFERENT
threads.

There is only a small problem.
I have written a very small VB6 program with a timer of 10ms.
At each tick it resize the form.
I have ran this program, then during it was working I have tried to iconify.
VB6 says me that it is not possible resizing during iconify.

I realize that I’m trying very strange things.
I’m doing in this way because I would like to understand the limits of
my applications.

It could be interesting if during window resize, SDL disables the
iconify/maximize window.

Thanks for your interest.
Paolo MinazziOn Mon, Sep 22, 2008 at 11:57 AM, Gabriele Greco <gabriele.greco at darts.it> wrote:

On Mon, Sep 22, 2008 at 8:27 AM, Paolo Minazzi <@Paolo_Minazzi> wrote:

Liam, thanks for your interest.
I have studied my problem and I realize that resizing SDL window has
to be done when SDL_Poll is not running. This solve one problem.
The other problem occour when pass from iconify-window to "normal
window) (on the screen).
If during this step I change resolution (this is my test) I have problem.
I understand that this is a very very very strange case and noone use it.
I was doing this test to verify some race condition problem.

The fact is that SDL video API calls should be performed on the main thread,
the fact it may work if something else doesn’t occur it may be true on
windows but not on other archs or with other versions of SDL, I suggest you
to build a SDL userevent in your thread and let the main thread perform the
Flip call in his loop.

Also be sure to use software surfaces, otherwise in HW surfaces “pixels” can
be null if surface is not locked, and you cannot lock a surface if you are
not the video thread owner…


Bye,
Gabry


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