Making a screen shot

Hi

I am having a problem with creating a shot of my screen. The screen is
doublebuffered, and I have been using the following code to capture it:

SDL_LockSurface(Screen);
background = SDL_CreateRGBSurface(SDL_SRCALPHA, Screen->w, Screen->h, 
			      Screen->format->BitsPerPixel,
			      Screen->format->Rmask,
			      Screen->format->Gmask,
			      Screen->format->Bmask,
			      Screen->format->Amask);
SDL_UnlockSurface(Screen);
if (background) {
  SDL_Rect d;
  d.x = 0; d.y = 0; 
  d.w = background->w;
  d.h = background->h;
  SDL_LockSurface(Screen); // If I lock, no crash, but no screen too
  SDL_BlitSurface(Screen, &d, background, &d);
  SDL_UnlockSurface(Screen); 
  SDL_SetAlpha(background, SDL_SRCALPHA, 64);
}

The problem is the second locking pair. If I do not lock, most of the time
I get a screen shot into background, but once in a while I get a crash in
SDL_SetAlpha (weird in it self). If I lock, I do not get chrases, but I
dont get anything into background either (just a black screen).

I am a bit confused about this. Can anybody spot anything obvious I am
doing wrong?

Thanks,

Mads–
Mads Bondo Dydensborg. @Mads_Bondo_Dydensbor
I don’t even consider working for MS Shops, or shops with extensive MS
deployment anymore. These companies are rape victims, and too self-abusive to
get away. Why waste time trying to help those who will not help themselves?
- David C. Manchester

“Mads Bondo Dydensborg” wrote in message
news:mailman.1006942809.25905.sdl at libsdl.org

SDL_LockSurface(Screen);
background = SDL_CreateRGBSurface(SDL_SRCALPHA, Screen->w, Screen->h,
  Screen->format->BitsPerPixel,
  Screen->format->Rmask,
  Screen->format->Gmask,
  Screen->format->Bmask,
  Screen->format->Amask);
SDL_UnlockSurface(Screen);

‘Screen->format’, ‘Screen->w’, and ‘Screen->h’ can be accessed without
locking. If ‘Screen->format->Amask’ is 0 (which is probably the case), the
resulting surface will have per-surface alpha, otherwise it will get
per-pixel alpha. If you want per-surface alpha, maybe you should pass in an
explicit 0.

if (background) {
  SDL_Rect d;
  d.x = 0; d.y = 0;
  d.w = background->w;
  d.h = background->h;
  SDL_LockSurface(Screen); // If I lock, no crash, but no screen too
  SDL_BlitSurface(Screen, &d, background, &d);
  SDL_UnlockSurface(Screen);

The lock here is obviously wrong. Never blit from or to a locked surface.

  SDL_SetAlpha(background, SDL_SRCALPHA, 64);

This should not crash. If you can write a correct minimal program that
reproduces this crash, then it is probably caused by a bug in SDL.
Otherwise it is probably caused by a bug elsewhere in your program.> }


Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

“Mads Bondo Dydensborg” <@Mads_Bondo_Dydensbor> wrote in message
news:mailman.1006942809.25905.sdl at libsdl.org

SDL_LockSurface(Screen);
background = SDL_CreateRGBSurface(SDL_SRCALPHA, Screen->w, Screen->h,

‘Screen->format’, ‘Screen->w’, and ‘Screen->h’ can be accessed without
locking. If ‘Screen->format->Amask’ is 0 (which is probably the case), the
resulting surface will have per-surface alpha, otherwise it will get
per-pixel alpha. If you want per-surface alpha, maybe you should pass in an
explicit 0.
Thanks, I will.

if (background) {
  SDL_Rect d;
  d.x = 0; d.y = 0;
  d.w = background->w;
  d.h = background->h;
  SDL_LockSurface(Screen); // If I lock, no crash, but no screen too
  SDL_BlitSurface(Screen, &d, background, &d);
  SDL_UnlockSurface(Screen);

The lock here is obviously wrong. Never blit from or to a locked surface.

Hmm. Could you point me at information explaining why?

  SDL_SetAlpha(background, SDL_SRCALPHA, 64);

This should not crash. If you can write a correct minimal program that
reproduces this crash, then it is probably caused by a bug in SDL.
Otherwise it is probably caused by a bug elsewhere in your program.

I am quite certain it is a bug in my program - my usage and knowledge of
SDL is quite new, and has large holes in it. I was hoping someone could
point me to reasons as to why it might fail.

MadsOn Wed, 28 Nov 2001, Rainer Deyke wrote:


Mads Bondo Dydensborg. @Mads_Bondo_Dydensbor
You may not use the Software in connection with any site that disparages
Microsoft, MSN, MSNBC, Expedia, or their products or services, infringe any
intellectual property or other rights of these parties, violate any state,
federal or international law, or promote racism, hatred or pornography.
- Part of MS Frontpage 2002 EULA

“Mads Bondo Dydensborg” wrote in message
news:mailman.1006973585.3355.sdl at libsdl.org

The lock here is obviously wrong. Never blit from or to a locked
surface.

Hmm. Could you point me at information explaining why?

SDL documentation under ‘SDL_LockSurface’:

No operating system or library calls should be made between lock/unlock
pairs, as critical system locks may be held during this time.> On Wed, 28 Nov 2001, Rainer Deyke wrote:


Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

“Mads Bondo Dydensborg” <@Mads_Bondo_Dydensbor> wrote in message
news:mailman.1006973585.3355.sdl at libsdl.org

The lock here is obviously wrong. Never blit from or to a locked
surface.

Hmm. Could you point me at information explaining why?

SDL documentation under ‘SDL_LockSurface’:

No operating system or library calls should be made between lock/unlock
pairs, as critical system locks may be held during this time.

Ah, my mistake. I read that as meaning no system calls, no libc
calls. Obviously that does not make sense.

Thanks,

MadsOn Wed, 28 Nov 2001, Rainer Deyke wrote:

On Wed, 28 Nov 2001, Rainer Deyke wrote:


Mads Bondo Dydensborg. @Mads_Bondo_Dydensbor
The Microsoft Dictionary:

       interoperability: The ability of a Microsoft product to operate
                         with another Microsoft product.