Jump to content
  • Advertisement
Sign in to follow this  
FireViper

free(TextureImage[0]) function error

This topic is 4972 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 }

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
QUOTE{
TextureImage[0]
}ETOUQ

Arrays are evil....Just as evil as overloading the operator[]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!