SDL_UpperBlit: Passed mismatched rectangles?

forgive the newbie question, but i’m working my way through the intro
code in the SDL DOC project, and have come across the error
"SDL_UpperBlit: Passed mismatched rectangles" when trying to blit a
bitmap onto the screen. The code works fine when the bitmap is the exact
same dimensions as the screen surface, but if the bitmap is smaller then
i get the error. I am using SDL 1.2.0 and running this in X under linux
(kernel 2.2.16-22).

looking at the image and screen surface clip_rects in gdb with a
breakpiont at the SDL_BlitSurface call, they both have h=0, which
mystifies me. I also tried using SDL_SetClipRect( …, NULL ) to set the
surface’s clip_rects to the whole surface, but the linker couldn’t find
SDL_SetClipRect (which also mystifies me - how could compile without
complaining and it link to all the other SDL functions but just not find
this one?)

here is source …

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

int main(int argc, char **argv) {

SDL_Surface *screen, *image;

/* init SDL library */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf( stderr, “Couldn’t initialize SDL: %s\n”, SDL_GetError());
exit(-1);
}

/* clean up at exit */
atexit(SDL_Quit);

/* init display to 640x480 8bpp palettized mode w/ software surface */
screen = SDL_SetVideoMode(800, 600, 8, SDL_SWSURFACE|SDL_ANYFORMAT);
if( screen == NULL ) {
fprintf( stderr, “Couldn’t set 640x480x8 video mode: %s\n”,
SDL_GetError());
exit(-1);
}

printf(“Set 640x480 at %d bits-per-pixel mode\n”,
screen->format->BitsPerPixel);

/* load in a BMP image */
image = SDL_LoadBMP(argv[1]);
if(image==NULL) {
fprintf(stderr, “Couldn’t load %s: %s\n”, argv[1], SDL_GetError());
return;
}

/* if this is a palettized screen mode, use the image’s color palette */
if(image->format->palette && screen->format->palette) {
SDL_SetColors(screen, image->format->palette->colors, 0,
image->format->palette->ncolors);
}

/* blit onto the screen surface */
if(SDL_BlitSurface(image, NULL, screen, NULL) < 0 )
fprintf(stderr, “BlitSurface error: %s\n”, SDL_GetError());

SDL_UpdateRect(screen, 0,0, image->w, image->h);

/* free the allocated BMP surface */

SDL_FreeSurface(image);

getc(stdin);

exit(0);
}

forgive the newbie question, but i’m working my way through the intro
code in the SDL DOC project, and have come across the error
"SDL_UpperBlit: Passed mismatched rectangles" when trying to blit a
bitmap onto the screen.

I can’t find that error message anywhere in the source. Are you sure
you aren’t using a very old SDL version, perhaps mismatching headers?
Make sure you remove every trace of your old SDL (headers, libraries,
sdl-config stuff etc) before installing a new one

“Paolo Piselli” wrote in message
news:3B29A9CE.8020303 at SPAMNO.yahoo.com

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

int main(int argc, char **argv) {

SDL_Surface *screen, *image;

/* init SDL library */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf( stderr, “Couldn’t initialize SDL: %s\n”, SDL_GetError());
exit(-1);
}

/* clean up at exit */
atexit(SDL_Quit);

/* init display to 640x480 8bpp palettized mode w/ software surface */
screen = SDL_SetVideoMode(800, 600, 8, SDL_SWSURFACE|SDL_ANYFORMAT);
^^^ ^^^

Should be 640 and 480, or you need to change your comments. Also,
‘SDL_ANYFORMAT’ is pointless if you use ‘SDL_SWSURFACE’.

if( screen == NULL ) {
fprintf( stderr, “Couldn’t set 640x480x8 video mode: %s\n”,
SDL_GetError());
exit(-1);
}

printf(“Set 640x480 at %d bits-per-pixel mode\n”,
screen->format->BitsPerPixel);

/* load in a BMP image */
image = SDL_LoadBMP(argv[1]);
if(image==NULL) {
fprintf(stderr, “Couldn’t load %s: %s\n”, argv[1], SDL_GetError());
return;
}

/* if this is a palettized screen mode, use the image’s color palette */
if(image->format->palette && screen->format->palette) {
SDL_SetColors(screen, image->format->palette->colors, 0,
image->format->palette->ncolors);
}

/* blit onto the screen surface */
if(SDL_BlitSurface(image, NULL, screen, NULL) < 0 )
^^^^ ^^^^

If the source rectangle is NULL, the entire source surface is used. If the
destination rectangle is NULL, the entire destination surface is used. The
source rectangle needs to have the same width and height as the destination
recatngle.> fprintf(stderr, “BlitSurface error: %s\n”, SDL_GetError());

SDL_UpdateRect(screen, 0,0, image->w, image->h);

/* free the allocated BMP surface */

SDL_FreeSurface(image);

getc(stdin);

exit(0);
}


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

‘SDL_ANYFORMAT’ is pointless if you use ‘SDL_SWSURFACE’.

not at all, it allows the screen buffer to be of a format different from
what was requested, which avoids conversion at update time

If the source rectangle is NULL, the entire source surface is used. If the
destination rectangle is NULL, the entire destination surface is used. The
source rectangle needs to have the same width and height as the destination
recatngle.

no, the width/height of the dest rect is ignored anyway. It’s documented

there were some old SDL 1.1 libraries hanging around in my /usr/lib/
replacing them with the SDL 1.2 libraries form /usr/local/lib fixed all
errors. Thanks!> I can’t find that error message anywhere in the source. Are you sure

you aren’t using a very old SDL version, perhaps mismatching headers?
Make sure you remove every trace of your old SDL (headers, libraries,
sdl-config stuff etc) before installing a new one