SDL_BlitSurface() error

hi,

I am kinda new to SDL (a couple of hours) and I am stuck. i am trying to load
a bmp image on a surface. Here’s the code , the screen just initializes and
closes(after the delay) and I get this SDL_BlitSurface() error :-

SDL_UpperBlit: passed a NULL surface. The docs say if NULL is passed the
entire surface is copied, that does’nt seem to be happening.

thanks for your time

Nasir----------------------------------
#include “SDL.h”

void display_bmp(SDL_Surface *screen,char *file_name)
{
SDL_Surface *image;

image = SDL_LoadBMP(file_name);
if(image=NULL)
{
	printf("failed loading image \n");
}

if((SDL_BlitSurface(image,NULL,screen,NULL))<0)
	printf("Error BlitSurface : %s\n",SDL_GetError());

SDL_UpdateRect(screen,0,0,0,0);

 /* Free the allocated BMP surface */
  SDL_FreeSurface(image);

}

int main()
{
// Initialize SDL-Video Subsystem
if(SDL_Init(SDL_INIT_VIDEO)<0)
{
printf(“Could Not Initialize the SDL-VIDEO Subsystem %s”,SDL_GetError());
exit(1);
}

// Initialize tje SDL-Audio Subsystem
if(SDL_InitSubSystem(SDL_INIT_AUDIO)<0)
{
	printf("Could Not Initialize the SDL-AUDIO Subsystem %s",SDL_GetError());
}

// Clean up resources on Exit : SDL_Quit() shutsdown all subsystems
atexit(SDL_Quit);		


// Set up Video Mode
SDL_Surface *screen;

// SDL_Surface *SDL_SetVideoMode(height,width,bits-per-pixel,flags)

screen = SDL_SetVideoMode(640,480,0,SDL_SWSURFACE|SDL_ANYFORMAT); 
if(screen==NULL)
{
	printf("Cannot set Video Mode %s",SDL_GetError());
	exit(1);
}
printf("Set video mode at 640x480 at %d 

bits-per-pixel\n",screen->format->BitsPerPixel);

display_bmp(screen,"background.bmp");

SDL_Delay(1000);		// wait for 1000 milliseconds before returning

return 0;

}

if(image=NULL)
{
printf(“failed loading image \n”);
}

This test is wrong, you must pass if(image == NULL )

So with image=NULL you set a NULL surface to image and application crash.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

MNH schrieb:
| SDL_UpperBlit: passed a NULL surface. The docs say if NULL is passed the
| entire surface is copied, that does’nt seem to be happening.

You passed a NULL surface not a rect. I think your file couldn’t be
opend or doesn’t exist.

| void display_bmp(SDL_Surface *screen,char *file_name)
| {
| SDL_Surface *image;
|
| image = SDL_LoadBMP(file_name);
| if(image=NULL)
| {
| printf(“failed loading image \n”);
~ return;
insert this ^^^^^^^
why blit a surface, which doesn’t exist?

The rest looks good, maybe this is your error.

HTH
Alexander

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBLeCtafA7tk6JB1ERAv0CAJ47qOtS03ys7V2gZDl4IWyZxRC32QCgimOw
LQx3NEjpMR+xTGwVaThDEgY=
=+xWo
-----END PGP SIGNATURE-----

To avoid assignment instead of comparison use “if (NULL == image) …”.
Then the compiler will complain about “if (NULL = image)…”…

Sorry for OT… but this must have been said :wink:

WalterAm Donnerstag, 26. August 2004 14:21 schrieb Carlos Alvarez:

if(image=NULL)
{
printf(“failed loading image \n”);
}

This test is wrong, you must pass if(image == NULL )

So with image=NULL you set a NULL surface to image and application crash.

hi everyone,

real dumb of me to miss that typo.

thanks again
nasirOn Thursday 26 August 2004 18:37, Alexander Stein wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

MNH schrieb:
| SDL_UpperBlit: passed a NULL surface. The docs say if NULL is passed the
| entire surface is copied, that does’nt seem to be happening.

You passed a NULL surface not a rect. I think your file couldn’t be
opend or doesn’t exist.

| void display_bmp(SDL_Surface *screen,char *file_name)
| {
| SDL_Surface *image;
|
| image = SDL_LoadBMP(file_name);
| if(image=NULL)
| {
| printf(“failed loading image \n”);

~ return;
insert this ^^^^^^^
why blit a surface, which doesn’t exist?

The rest looks good, maybe this is your error.

HTH
Alexander

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBLeCtafA7tk6JB1ERAv0CAJ47qOtS03ys7V2gZDl4IWyZxRC32QCgimOw
LQx3NEjpMR+xTGwVaThDEgY=
=+xWo
-----END PGP SIGNATURE-----


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl