A problem with BlitSurface

Hello;

I have this program:

#include <stdio.h>
#include <stdlib.h>
#include “SDL.h”
//#include “SDL_ttf.h”
#include “SDL_gfxPrimitives.h”

int main()
{
int Salir, Guardian;

SDL_Event event;

SDL_Surface *Fondo, *Pantalla;
SDL_Surface *Enemigo1;

SDL_Rect Origen, Destino;

// Iniciar SDL
Guardian=SDL_Init(SDL_INIT_VIDEO);
if (Guardian<0) { printf("\nError iniciando SDL_Video"); }

// Modo de video 640x480
Fondo=SDL_SetVideoMode(640,480,8,SDL_SWSURFACE);
if (Fondo=NULL) { printf("\nError iniciando la resolucion"); }

// Mostramos un fondo
Enemigo1=SDL_LoadBMP("Fuentes/Enemigo1.bmp");
if (Enemigo1==NULL) { printf("\nNo se cargo el fondo: %s \n", 

SDL_GetError()); }

Origen.x=5;
Origen.y=5;
Origen.w=640;
Origen.h=480;

Destino.x=10;
//printf("\nError en Destino: %s \n", SDL_GetError());
Destino.y=10;
//printf("\nError en Destino: %s \n", SDL_GetError());
Destino.w=Enemigo1->w;
//printf("\nError en Destino: %s \n", SDL_GetError());
Destino.h=Enemigo1->h;
//printf("\nError en Destino: %s \n", SDL_GetError());

SDL_UnlockSurface(Enemigo1);
//SDL_UnlockSurface (Pantalla);

//Guardian=SDL_BlitSurface(Enemigo1,&Origen,Pantalla,&Destino);
Guardian=SDL_BlitSurface(Enemigo1,NULL,Pantalla,NULL);
if (Guardian<0) { printf("\nSDL_BlitSurface: %s \n", SDL_GetError()); }

//SDL_UpdateRect(Pantalla,0,0,0,0);

//SDL_LockSurface(Enemigo1);

Guardian=SDL_Flip(Pantalla);
if (Guardian<0) { printf("\nSDL_Flip: %s \n", SDL_GetError()); }

//SDL_FreeSurface(Enemigo1);

Salir=0;
while (Salir<1)
{
	while (SDL_PollEvent(&event))
	{
		if (event.type==SDL_KEYDOWN) Salir=1;
	}
}
return 0;

}

The error says:

SDL_BlitSurface: Surfaces must not be locked during blit

What is bad in the program? :?_________________________________________________________________
Moda para esta temporada. Ponte al d?a de todas las tendencias.
http://www.msn.es/Mujer/moda/default.asp

Hi,

Selon ALTAIR - :

SDL_Surface *Fondo, *Pantalla;

Guardian=SDL_BlitSurface(Enemigo1,NULL,Pantalla,NULL);
if (Guardian<0) { printf("\nSDL_BlitSurface: %s \n", SDL_GetError()); }

What is bad in the program? :?

The Pantalla pointer is not initialized before you use it.

Your compiler is very bad or misused if it did not warn you about this. Use
another compiler or turn warnings on.

Regards,

Xavier

ALTAIR - wrote:

SDL_UnlockSurface(Enemigo1);

You unlock a bitmap that is not locked, this may flip the lock counter.

Guardian=SDL_BlitSurface(Enemigo1,NULL,Pantalla,NULL);

As said in the other reply, Pantalla is not initialized anywhere.

Bye,
Gabry