You are not logged in.

#1 2011-12-01 08:05:43

wilco2009
Member

jpg images crashes loading twice

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.

Code:

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

    nombre[0]=0;
    strcat(nombre,DirActivo);
    strcat(nombre,lista[i]);
    tex_foto = GRRLIB_LoadTextureFromFile(nombre);
    GRRLIB_SetMidHandle(tex_foto,true);
}

and the code in main to show the image is:

Code:

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 possible to show an image with resolution not multiply by 4?

Last edited by wilco2009 (2011-12-05 09:37:44)

Offline

 

#2 2011-12-03 12:17:49

owen
Member

Re: jpg images crashes loading twice

Do not  GRRLIB_FreeTexture(tex_foto); you need to keep the memory available for the next time you draw the image.

I suggest that you make  tex_foto[i] an array.

Images have to be multiple of 4 or even.

Offline

 

#3 2011-12-03 13:58:27

wilco2009
Member

Re: jpg images crashes loading twice

Yes, I thought on that, but, LoadTextureFromFile uses LoadTextureJPGEx (through LoadTexture and LoadTextureJPG) and it reserve memory for the new texture with memalign:

Code:

     my_texture->data = memalign(32, cinfo.output_width * cinfo.output_height * 4);

In my program, exactly the same code works perfectly if the image is a png.

Last edited by wilco2009 (2011-12-03 14:00:14)

Offline

 

#4 2011-12-04 00:51:56

owen
Member

Re: jpg images crashes loading twice

hmmm, then I have no idea, I've only used pngs.

Offline

 

#5 2011-12-05 21:15:22

wilco2009
Member

Re: jpg images crashes loading twice

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.

Offline

 

Board footer

Powered by FluxBB