free(TextureImage[0]) function error

Started by
14 comments, last by Enigma 19 years, 4 months ago
When I try to compile the following code, I always get an error saying "implicit declaration of function int free(...)" What am I doing wrong? if (TextureImage[0]) // If Texture Exists { if (TextureImage[0]->data) // If Texture Image Exists { free(TextureImage[0]->data); // Free The Texture Image Memory } free(TextureImage[0]); // Free The Image Structure }
Advertisement
odd...did you include malloc?
malloc? what is that a header or a lib?

To include malloc and free, you just need to do:
#include <stdlib.h>
“[The clergy] believe that any portion of power confided to me, will be exerted in opposition to their schemes. And they believe rightly: for I have sworn upon the altar of God, eternal hostility against every form of tyranny over the mind of man” - Thomas Jefferson
Did you write those lines in a function or out of everything? Some days I tried to call a function before entering the winMain function and I got nearly the same error.
for some reason stdlib.h wasn't in my comp, after reinstalling it, I was able to compile the program with an error

one more thing, How do I load mutliple textures?
Every time I try, I the progarm compiles but dosen't run

QUOTE{
TextureImage[0]
}ETOUQ

Arrays are evil....Just as evil as overloading the operator[]
ok, so if I want to laod one texture I would use the following code,
if (TextureImage[0]=LoadBMP("Pic1.bmp"))	{		Status=TRUE;									// Set The Status To TRUE		glGenTextures(2, &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])									// If Texture Exists	{		if (TextureImage[0]->data)						{			free(TextureImage[0]->data);					}		free(TextureImage[0]);						}


But when I try to add a second texture,

if (TextureImage[0]=LoadBMP("Pic2.bmp"))	{		Status=TRUE;									// Set The Status To TRUE		glGenTextures(2, &texture[1]);								glBindTexture(GL_TEXTURE_2D, texture[2]);		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data);		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	}	if (TextureImage[1])									// If Texture Exists	{		if (TextureImage[1]->data)						{			free(TextureImage[1]->data);					}		free(TextureImage[1]);						}


It dosen't work
Two errors there (possibly three).
  1. TextureImage[0]=LoadBMP("Pic1.bmp")
    ...
    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data);
    You load the texture into TextureImage[0] but access it from TextureImage[1]

  2. glBindTexture(GL_TEXTURE_2D, texture[2]);
    You bind texture[2] when you probably want texture[1]. It's not necessarily an error, but it's odd.

  3. Are your arrays big enough? Both TextureImage and texture need to be big enough for at least two elements the way you are doing things.


Enigma

This topic is closed to new replies.

Advertisement