tags:

views:

79

answers:

4

Here's a BIG problem with my project:

I love the tutorials on the NeHe website, and Windows XP ran the programs perfectly. However, when I reformatted my computer, changed the OS to Windows Vista and reinstalled my Dev-C++ compiler, and then I tried to open any C++ program that used textures, the program crashed.

I realised my glaux.h went missing. I found the file on the Internet and recompiled my project, but it still crashed. Everything went well when I excluded the texture functions.

Where does the problem lie and what can I do to solve it?

I was thinking one of these is the culprit: Windows Vista OS, my graphics card, glaux.h and libraries (I know it's bugged), OpenGL itself.

.

Update: I determined the source of the problem.

This chunk of code caused my program to crash:

if (TextureImage[0]) {
    if (TextureImage[0]->data) {    
    free(TextureImage[0]->data);
    }
    free(TextureImage[0]);
}

For some reason, my program always crashes whenever I order it to free memory. When I commented this section off, my program works fine, except that all the colours went dark (I'm thinking it's because of the colours of my bitmap file). Any tips?

.

Reply to: Matias Valdenegro

Well, this was derived from NeHe lesson6 which worked fine when I still used Windows XP. Absolutely nothing was changed when I switched to Windows Vista.

Just so you know, here's the entire function:

#define NoOfTextures 3
GLuint  texture[NoOfTextures];

int LoadGLTextures()
{
    int Status=FALSE;

    AUX_RGBImageRec *TextureImage[NoOfTextures];

    memset(TextureImage,0,sizeof(void *)*1);

    if (TextureImage[0]=LoadBMP("Data/Bitmaps/texture.bmp"))
    {
        Status=TRUE;

        glGenTextures(1, &texture[0]);

        glBindTexture(GL_TEXTURE_2D, texture[0]);
        glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

        if (TextureImage[0] != NULL) {  
            if (TextureImage[0]->data != NULL) {    
                free(TextureImage[0]->data);
            }
            free(TextureImage[0]);  
        }
    }

    return Status;                                      
}

.

Additional Information:

I rebuild my project often and LoadBMP() is part of the same header file. This is the LoadBMP() function:

AUX_RGBImageRec *LoadBMP(char *Filename)
{
    FILE *File=NULL;

    if (!Filename)
    {
        return NULL;
    }

    File=fopen(Filename,"r");

    if (File)
    {
        fclose(File);
        return auxDIBImageLoad(Filename);
    }

    return NULL;
}

This seems pretty clear cut to me.

A: 

I'm guessing it has to do with file permissions. Try setting the file permissions of your project to a lower level (specially your textures). This happened to me in the past as well on different projects that load assets at runtime, when I switched to Vista or Win7 from XP.

Seth Illgard
+1  A: 

As it's crashing in a free call, check

  • That you're not double freeing pointers.
  • That you have valid pointers anywhere. This means free pointers allocated using malloc, you can't free a pointer obtained with new. Also, you must free the original pointer value you got from the allocation function, not the pointer + 1 or some arithmetic on it.
Matias Valdenegro
A: 

Is the memory being allocated (with malloc) in a library that you are not recompiling, and then freed in freshly compiled code? Different compiler/OS combinations use the heap differently, so mismatched malloc/free between two libraries compiled under different circumstances may cause a crash (or some other UB).

Specifically, are you sure that you're compiling the implementation of LoadBMP() since your reinstall?

Alan
A: 

Case Closed:

I was editing my bitmap (NeHe lesson7's Crate.bmp) when I realised the colours I painted on it did not show right. After creating a new 24-bit bitmap and marking colours on it, the white background went orange, but this was because of my previous glColor3f() call. I added a glColor3f(1.0f, 1.0f, 1.0f) call and commented off that section of code with the free() in it, and everything went swell.

EoS
I also had to load a 'blank' texture (white bitmap) at the end of my program for colour correction.
EoS