[SDL] Core dumped while SDL_FillRect or SDL_BlitSurface

Ignacio Lorenzo Subirá Otal nachootal at salle.url.edu
Tue Oct 23 03:05:13 PDT 2007


Hi all!, I'm new to the list and I already have questions to ask...
I recently started to develop under SDL in a Ubuntu box and I have a
headeache with a function.
It just core dump's when I execute it when I perform a SDL_FillRect or a
SDL_BlitSurface.
I don't know why this can be because all seems to be right so I'll post
you the code and the error I get when executing.

This is the function and the structure I use and as attachement I send
you all the code.
 info is a global variable.
void LetrasArribaLetrasAbajo()
{
    // Se muestran letras arriba y abajo sobre un fondo negro
	SDL_Surface *textoa = NULL , *textob = NULL;
	SDL_Rect rectangulo1, rectangulo2, parte1, parte2;
	TTF_Font *fuente = NULL;
	char textoamostrar[20];
	float altura;
	int valor;
	fuente = TTF_OpenFont("Telegraphem.ttf", 75);//rutafuente1, 75);
	// Acoto los dos textos
	printf("Estoy en los textos\n");
	strcpy(textoamostrar, "info.texto1");
	//textoa = TTF_RenderText_Solid(fuente, "HOLA", *info.ColorFuente1);	
	textoa = TTF_RenderText_Solid(info.Fuente1, info.texto1,
*info.ColorFuente1);	
	strcpy(textoamostrar, info.texto2);
	textob = TTF_RenderText_Solid(fuente, info.texto2, *info.ColorFuente2);
	//textob = TTF_RenderText_Solid(info.Fuente2, "ADIOS",
*info.ColorFuente2);
	parte1.w = textoa->w;
	parte1.h = textoa->h;
	parte2.w = textob->w;
	parte2.h = textob->w;
	// Calculo la posicion en las que voy a centrar ambas informaciones
	altura = parte1.h + parte2.h;
	// Sobrante
	altura = info.h - altura;
	printf("Altura sobrante %f\n", altura);
	// Habr’a que controlar el error aqu’
	// Reparto el sobrante en 3 y los distribuyo as’
	// Sobrante/3
	// Texto1
	// Sobrante/3
	// Texto2
	// Sobrante/3
	altura = altura / 3;
	printf("Altura entre textos %f\n", altura);
	parte1.y = info.y + (int) altura;
	printf("Altura texto 1 %d\n", parte1.y);
	parte2.y = parte1.y + parte1.h + (int) altura;
	printf("Altura texto 2 %d\n", parte2.y);
	// Tengo que centrar los textos en la horizontal
	parte1.x = info.x + (int) ((info.w - parte1.w)/2);
	parte2.x = info.x + (int) ((info.w - parte2.w)/2);
	// Acoto los rect‡ngulos para los fondos
	rectangulo1.x = info.x;
	rectangulo1.y = info.y;
	rectangulo1.w = info.w;
	rectangulo1.h = parte1.h + (int) (3*altura/2); // Dejo los fondos a
mitad de fusi—n entre los dos textos
	rectangulo2.x = rectangulo1.x;
	rectangulo2.y = info.y + rectangulo1.h;
	rectangulo2.w = info.w;
	rectangulo2.h = parte2.h + (int) (3*altura/2);
	// Llegados aqu’, tengo las m‡scaras para pintar en la pantalla, parte1
y parte2.
	// Pongo los fondos
	SDL_FillRect(info.Pantalla, &rectangulo1,
SDL_MapRGB(info.Pantalla->format, info.ColorFondo1->r,
info.ColorFondo1->g, info.ColorFondo1->b)); // IT CRASHES HERE
	SDL_FillRect(info.Pantalla, &rectangulo2,
SDL_MapRGB(info.Pantalla->format, info.ColorFondo2->r,
info.ColorFondo2->g, info.ColorFondo2->b)); // ALSO CRASHES HERE IF I
COMMENT THE OTHER SDL_FillRect
	// Pongo los textos
	printf("Rectangulo 1 destino\n");
	printf("x %d\n", parte1.x);
	printf("y %d\n", parte1.y);
	printf("w %d\n", parte1.w);
	printf("h %d\n", parte1.h);	
	printf("Texto a Mostrar: %s\n", info.texto1);
	printf("Rectangulo 2 destino\n");
	printf("x %d\n", parte2.x);
	printf("y %d\n", parte2.y);
	printf("w %d\n", parte2.w);
	printf("h %d\n", parte2.h);
	printf("Texto a Mostrar: %s\n", info.texto2);
	/*textoa = SDL_LoadBMP("imagen.bmp");
	scanf("%d", &valor);*/
	SDL_BlitSurface(textoa, NULL, info.Pantalla, &parte1); // ALSO HERE IF
I COMMENT THE UPPER ERRORS
	SDL_BlitSurface(textob, NULL, info.Pantalla, &parte2); // AND HERE IF I
COMMENT THE UPPER BlitSurface
	// Lo saco todo por pantalla
	SDL_Flip(info.Pantalla);
	// Libero la memoria que he cogido
	SDL_FreeSurface(textoa);
	SDL_FreeSurface(textob);
	// Ya puedo salir
	//scanf("%d", &valor);
}

// THE STRUCTURE

ypedef struct info_pantalla {
    // Espero que se me inicialize todo aunque sea con NULL
    char rutaicono1[20];
    char rutaicono2[20];
    TTF_Font *Fuente1;
    TTF_Font *Fuente2;
    SDL_Color *ColorFondo1;
    SDL_Color *ColorFuente1;
    char texto1[20];
    SDL_Color *ColorFondo2;
    SDL_Color *ColorFuente2;
    char texto2[20];
    SDL_Surface *Pantalla;
    int x, y, w, h;
    char blink1, blink2;
}info_pantalla;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: Blinks.c
Type: text/x-csrc
Size: 11005 bytes
Desc: not available
Url : http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20071023/558ed019/attachment.c 


More information about the SDL mailing list