1

I am performing SDL_BlitSurface(s_pScreen, 0, s_pScreen, 0); in order to make the display black as below.

It works but sometimes it seems like it crashes. I get the error message "The exception Privileged Instruction. (0xC0000096) occured in the application at location (0x00700070)"

Program:

  Lock lock(&s_layer_cs);
     // clear the back buffer
     SDL_FillRect(s_pScreen, NULL, 0);
     // Blit each layer to the back buffer
     for (int i = 0; i < s_layers; ++i)
     {
        if (!s_layer_disabled[i])
        {
           if (0U == IlluminationCmd)
           {
           //Make the display black
           SDL_BlitSurface(s_pScreen, 0, s_pScreen, 0);
           }
           else
           {
          SDL_BlitSurface(s_pSurface[i], 0, s_pScreen, 0);
           }
        }
     }
     // Flip buffers
     SDL_Flip(s_pScreen);
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
user1032187
  • 201
  • 1
  • 2
  • 8

2 Answers2

1

SDL can handle overlapping blits and in this case the two surfaces. You can see this in "SDL_blit.c" and depending on how you are looking at the file, look at lines 308 or line 298 as reported by others. The line checks for the source and the destination being the same and handles it.

if ( surface == surface->map->dst ) {
                surface->map->sw_data->blit = SDL_BlitCopyOverlap;

If I had to guess it is not an error of the source and the destination being the same but an error with the screen itself.

EDIT: There are other ways to make the screen black. You actually do that at the beginning with SDL_FillRect(s_pScreen, NULL, 0); In fact, if you have anything blitted to the screen already or if the screen is a different color, SDL_BlitSurface(s_pScreen, 0, s_pScreen, 0); won't clear the screen to black. The only reason I can see it works there is because you are blitting it to itself right after you set the entire screen black.

Sam Walker
  • 104
  • 4
0

If you are still using SDL-1.2.13, then maybe it's similar to a bug we had. We fixed it by adding this just after the blit:

asm("cld");

Or if you are on Windows:

__asm{cld};

A debian bug report about it

Alink
  • 394
  • 2
  • 4