Problem with SDL on Centrino M and AMD 64 processors

I am in desparate need of help. I will be visiting the Game Developers Conference at the beginning of next week and have just found a problem in my game that I cannot seem to fix.

I am creating a hardware surface using SDL_CreateRGBSurface(). I then load a background image and blit it to this surface tiling it until it fills the whole surface. This makes up the background for my level.

This works flawlessly on any pentium III and IV processor I have tested it on. Recently I tested it on an AMD 64 processor and an Intel Pentium M processor and I get some serious graphical problems. The background shows up upside down, mirrored, sometimes it shows up filled with random colors from previous backgrounds on other levels.

I have narrowed the problem down to the fact that I am creating a surface as a SDL_HWSURFACE. If I simply change the flag to SDL_SWSURFACE it works flawlessly (however the frame rate is seriously affected).

If anyone has any suggestions as to what could be causing this please feel free to make any comments, suggestions, etc.

I have tried everything and I am still getting the same result. There is only one thing that seems to work but it is will not do for a final result. If I create both RGB surfaces as SDL_SWSURFACEs then convert them to SDL_HWSURFACEs via SDL_DisplayFormat() it shows up fine. However, when I try to blit from another surface to the background surface I get a frame rate of about 4 FPS.

Any suggestions, I am at a loss and the conference is comming up very quickly.

And another thing, on the Celeron M laptop I am testing it on, windowed mode does not work the window appears but no graphics are displayed. Any other window that passes over the canvas of my window will leave a trail. However, on the AMD 64 processor and the Pentium 4 and Pentium 3 processors I have tested this on it works flawlessly. I am so confused.

I appreciate any and all help in advance.

Here is some code:

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
Uint32 rmask = 0xff000000;
Uint32 gmask = 0x00ff0000;
Uint32 bmask = 0x0000ff00;
Uint32 amask = 0x000000ff;
#else
Uint32 rmask = 0x000000ff;
Uint32 gmask = 0x0000ff00;
Uint32 bmask = 0x00ff0000;
Uint32 amask = 0xff000000;
#endif

// Create surfaces large enough to fit the map
background = SDL_CreateRGBSurface(SDL_HWSURFACE, width * TILE_SIZE, height * TILE_SIZE, COLOR_DEPTH, rmask, gmask, bmask, amask);
originalBackground = SDL_CreateRGBSurface(SDL_HWSURFACE, width * TILE_SIZE, height * TILE_SIZE, COLOR_DEPTH, rmask, gmask, bmask, amask);

// Converting any created surfaces to the same format as the screen supposedly speeds up blitting
SDL_Surface *temp = SDL_ConvertSurface(background, screen->format, SDL_HWSURFACE);
SDL_FreeSurface(background);
background = temp;

temp = SDL_ConvertSurface(originalBackground, screen->format, SDL_HWSURFACE);

SDL_FreeSurface(originalBackground);
originalBackground = temp;

temp = SDL_ConvertSurface(tiles, screen->format, SDL_HWSURFACE | SDL_SRCCOLORKEY | SDL_RLEACCEL);
SDL_FreeSurface(tiles);
tiles = temp;

// Set transparency for the tile layer
if( SDL_SetColorKey(tiles, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(tiles->format, 255, 0, 255)) < 0)
{
ErrorHandler(“Could not set ColorKey + RLE for the background: %s\n”, SDL_GetError());
}

if(!background || !originalBackground) ErrorHandler(“Could not create background surface.”);

// The following code allows for a (“any width” x 352) background to be repeated for the entire
// length of the map’s width. If the map’s width is not evenly divisible by the width
// of the background, the remaining piece of the background is added.
{
directory = BACKGROUND_DIRECTORY;
file = directory + backgroundFilename;

    SDL_Surface *tempBackground = SDL_LoadBMP(file.c_str());
temp = SDL_ConvertSurface(tempBackground, screen->format, SDL_HWSURFACE);
SDL_FreeSurface(tempBackground);
tempBackground = temp;

    int i = 0;
for(i = 0; i < (width * TILE_SIZE) / tempBackground->w; i++)
{
	Blit(background, tempBackground, i * tempBackground->w, 0, 0, 0, tempBackground->w, tempBackground->h);
	Blit(originalBackground, tempBackground, i * tempBackground->w, 0, 0, 0, tempBackground->w, tempBackground->h);
}

int remainingPixels = (width * TILE_SIZE) % tempBackground->w;
if(remainingPixels != 0)
{
    Blit(background, tempBackground, i * tempBackground->w, 0, 0, 0, remainingPixels, tempBackground->h);
    Blit(originalBackground, tempBackground, i * tempBackground->w, 0, 0, 0, remainingPixels, tempBackground->h);
}

SDL_FreeSurface(tempBackground);

}

Are you locking the surface before writing to it?

Matthew> I am in desparate need of help. I will be visiting the Game Developers

Conference at the beginning of next week and have just found a problem in my
game that I cannot seem to fix.

I am creating a hardware surface using SDL_CreateRGBSurface(). I then load
a background image and blit it to this surface tiling it until it fills the
whole surface. This makes up the background for my level.

This works flawlessly on any pentium III and IV processor I have tested it
on. Recently I tested it on an AMD 64 processor and an Intel Pentium M
processor and I get some serious graphical problems. The background shows up
upside down, mirrored, sometimes it shows up filled with random colors from
previous backgrounds on other levels.

I have narrowed the problem down to the fact that I am creating a surface
as a SDL_HWSURFACE. If I simply change the flag to SDL_SWSURFACE it works
flawlessly (however the frame rate is seriously affected).

If anyone has any suggestions as to what could be causing this please feel
free to make any comments, suggestions, etc.
I have tried everything and I am still getting the same result. There is
only one thing that seems to work but it is will not do for a final result.
If I create both RGB surfaces as SDL_SWSURFACEs then convert them to
SDL_HWSURFACEs via SDL_DisplayFormat() it shows up fine. However, when I try
to blit from another surface to the background surface I get a frame rate of
about 4 FPS.

Any suggestions, I am at a loss and the conference is comming up very
quickly.

And another thing, on the Celeron M laptop I am testing it on, windowed
mode does not work the window appears but no graphics are displayed. Any
other window that passes over the canvas of my window will leave a trail.
However, on the AMD 64 processor and the Pentium 4 and Pentium 3 processors
I have tested this on it works flawlessly. I am so confused.
I appreciate any and all help in advance.