Display image errors

Hi,
I have a couple of problems regarding images that I wonder if others can
duplicate (and explain).
They may be entirely different problems, on the other hand they may
arise from the same
cause.
The problems concern errors in displaying images. Images do not display
at all without a delay inserted in the program
and they may not be displayed correctly.
I demonstrate the first with the code example from SDL_GetWindowSurface:

#include <SDL.h> // include SDL header

int main(int argc, char* argv[])
{
SDL_Surface *screen; // even with SDL2, we can still bring ancient
code back
SDL_Window *window;
SDL_Surface *image;

 SDL_Init(SDL_INIT_VIDEO); // init video

 // create the window like normal
 window = SDL_CreateWindow("SDL2 Example", SDL_WINDOWPOS_UNDEFINED, 

SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);

 // but instead of creating a renderer, we can draw directly to the 

screen
screen = SDL_GetWindowSurface(window);

 // let's just show some classic code for reference
 image = SDL_LoadBMP("box.bmp"); // loads image
 SDL_BlitSurface(image, NULL, screen, NULL); // blit it to the screen
 SDL_FreeSurface(image);

 // this works just like SDL_Flip
 SDL_UpdateWindowSurface(window);

 // show image for 2 seconds
 SDL_Delay(2000);
 SDL_DestroyWindow(window);
 SDL_Quit();
 return 0;

}

compiled with: gcc -o example -g -Wall -O0 -D_GNU_SOURCE sdl2-config --libs --cflags example.c

  1. The example gives no output to the window.
  2. Debugging step by step with gdb gives the expected image.
  3. Inserting ‘SDL_Delay(1000);’ after the ‘screen =
    SDL_GetWindowSurface(window);’ command gives the expected result.

The second problem seems to indicate a problem with a specific
resolution of the image.
Using the code with the delay , I try the same image at several resolutions:

  1. 100x100 works OK
  2. 1000x1000 works OK
  3. 200x200 shows some sort of clipping of the image in the region of the
    very dark pixels. These areas display in various colours.

If I replace ‘image = SDL_LoadBMP(“horse_200x200.bmp”);’ by ‘image =
IMG_Load(“horse_200x200.bmp”);’, the image is displayed correctly. But I
still need the delay to display anything.

I am running Debian wheezy (current stable) with Linux kernel 3.10.10-amd64.
I have reinstalled SDL2-2.0.1, the results don’t change.

Malcolm