jpg images crashes loading twice
December 05, 2011 09:34AM
I'm writting a GRRLIB tutorial for a Spanish web, and I'm finishing a chapter about textures.

The example code is a "image/music" viewer, and I found a problem with jpg images.

When I load a png image I haven't found problems with the same code (only resolution diferent than x4 files are not showed, but it is known), but if the image is a jpg the file is showed once but if I try to show the same or a second diferent image the program crashes in loading function.
I'm writting a GRRLIB tutorial for a Spanish web, and I'm finishing a chapter about textures.

The example code is a "image/music" viewer, and I found a problem with jpg images.

When I load a png image I haven't found problems with the same code (only resolution x4 files are not showed, but it is known), but if the image is a jpg the file is showed once but if I try to show the same or a second diferent image the program crashes in loading function.

void leeimagen(int i){
	if (tex_foto!=NULL)
		GRRLIB_FreeTexture(tex_foto);

	nombre[0]=0;
	strcat(nombre,DirActivo);
	strcat(nombre,lista);
	tex_foto = GRRLIB_LoadTextureFromFile(nombre);
	GRRLIB_SetMidHandle(tex_foto,true);
}
and the code in main to show the image is:

if (tipos[archivo_actual]==TIPO_IMAGEN){
	if(!leido) {
		angulo = 0;
		cursoractivo = 1;
		leeimagen(archivo_actual);
		leido = true;
	}
	if (tex_foto != NULL){
		GRRLIB_SetMidHandle(tex_foto, true);
		if ((angulo % 180) == 0){
			sfx = 480.0/tex_foto->w;
			sfy = 365.0/tex_foto->h;
		} else {
			sfy = 480.0/tex_foto->h;
			sfx = 365.0/tex_foto->w;
		}
	}
	if (tex_foto != NULL)
		GRRLIB_DrawImg(320-stx,(210-sty)*sy,tex_foto,angulo,sfx*zoom,sy*sfy*zoom,GRRLIB_WHITE);
	else
		GRRLIB_DrawImg(320,210*sy,tex_error,0,1,sy*1.0,GRRLIB_WHITE);
}

By other hand, is it possible to show an image with resolution not multiply by 4 using a diferent library?


EDITED:
Seems it happens only with some jpeg images, but valid images.

I tried to put only two GRRLIB_LoadImageFromFile calls on main with the same jpeg image and program freeze, but only with some jpeg images. Another jpeg images works fine.



Edited 1 time(s). Last edit at 12/05/2011 09:20PM by wilco2009.
Re: jpg images crashes loading twice
December 06, 2011 08:41PM
Your code snip looks ok, but you are using a single global variable named “tex_foto”
This limits you to just use one loaded image.
If that’s the way you designed it then that's fine, otherwise use another array like you have for the filename list "lista"



Edited 1 time(s). Last edit at 12/06/2011 08:41PM by Titmouse.
Re: jpg images crashes loading twice
December 06, 2011 11:14PM
I display only one file same time.
When user press a button, the program calls to function leeimagen, and in this function, before to load the new image, memory is released with GRRLIB_FreeTexture.

The program works fine with pngs, and some jpg files, but with others GRRLIB_LoadTextureFromFile crashes the following time I call the function.
This happens when you user press next and then back.
Re: jpg images crashes loading twice
December 07, 2011 10:14PM
That behavior does sound very odd. What happens if you call the texture loading twice just own its own as a test - does it still crash?
Jpg does have a few file variations (so some loaders can’t cope) but from what you say, it loads and works first time. I don’t use things like grrlib myself, so I not going to be much help beyond this point.

You could try
http://wiibrew.org/wiki/GameFramework
Look for x2 code files JPEGDEC. This is a lightweight jpg decoder; it’s no frills and will require more work with maybe less support for jpeg formats. I use it and it works well for me.
Re: jpg images crashes loading twice
December 08, 2011 12:37AM
Yes, if I do that you say, the image still crashing.
I thing it is a bug in the library.
By other hand, your library seems great. It is very interesting and I'll will try to use it in my programs.
Sorry, only registered users may post in this forum.

Click here to login