Jump to content
  • Advertisement
Sign in to follow this  
MajinMusashi

OpenGL glDeleteTextures crashing down!

This topic is 4827 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

Hi! I'm using Visual C++ 6.0, and I'm having some problem figuring out how to delete a single texture from OpenGL's memory. Please, take a look at my code:
// Texture class
class CTexture {
public:
   GLuint getIndex();
}

// Release OpenGL texture memory
void C_Manager::release( unsigned int index ) {
   if ( index != 0 ) {
      for ( it = textureVector.begin(); it != textureVector.end(); ++it ) {
         if ( (*it)->getIndex() == index ) {
            if ( (*it)->decRefCounter() == 0 ) {
               glDeleteTextures( 1, (*it)->getIndex() ); // LOOK HERE!!!!!
               textureVector.erase( it );
            }
            return;
         }
      }
   }
}

// Just to remember, glDeleteTextures prototype
void glDeleteTextures(
  GLsizei n,
  const GLuint * textures
);



The problem: Compiler error: "glDeleteTextures: cannot convert parameter 2 from 'unsigned int' to 'const unsigned int *'" OK, it's easy! Just tried a typecast like this: "glDeleteTextures( 1, (const GLuint*)(*it)->getIndex() )" and all compiles fine, but the execution of this function exits the running application. Can you help me? Note that I don't want to change "CTexture::getIndex()" return type, but the typecast needed from glDeleteTextures to accept it. Thanks a lot! PS.: "(*it)->getIndex()" returns a valid value PS.: There has been no detectable OpenGL error ("glGetError" returns GL_NO_ERROR) [Edited by - MajinMusashi on August 26, 2005 1:51:53 AM]

Share this post


Link to post
Share on other sites
Advertisement
void glDeleteTextures(
GLsizei n,
const GLuint * textures
);


glDeleteTextures() takes a pointer to the texture names (id's)

you have passed it a GLuint directly, if you change the getIndex like this:

class CTexture {
GLuint textureID;
public:
GLuint *getIndex();
}

GLuint *CTexture::getIndex()
{
return &textureID;
}



glDeleteTextures() takes a pointer to an array of texture names (id's)
It doesn't take one texture name to delete, it takes an array of texture names to delete.

if you do it like this:

GLuint *textureIDs;
GLsizei nTextureIDs;

// deleting the textures
glDeleteTextures(nTextureIDs,textureIDs);




Good luck with your project.


Share this post


Link to post
Share on other sites
Sorry, programering, but I wasn't clear enough: I don't want to change "CTexture::getIndex()" return type, I want to typecast its returned value (without crashing the entire application). Is there any way I can do that?

Thanks!

Share this post


Link to post
Share on other sites
If you don't want to adapt your function for glDeleteTextures, and since you can't adapt glDeleteTextures for your functions, you have to implement a glue layer between the two; store the returned value in a separate variable and pass the address of that variable.

GLuint ID = (*it)->getIndex();
glDeleteTextures(1, &ID);

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
If you don't want to adapt your function for glDeleteTextures, and since you can't adapt glDeleteTextures for your functions, you have to implement a glue layer between the two; store the returned value in a separate variable and pass the address of that variable.
GLuint ID = (*it)->getIndex();
glDeleteTextures(1, &ID);

Thanks, Brother Bob! But I'm still curious about the crashes and how to do a correct typecasting on "getIndex()" to avoid compiler errors and application crashes.

Goodbye!!!

Share this post


Link to post
Share on other sites
The reason it crashed was that you passed a value to a function expecting the address of a value. Incompatible types, and there's nothing you can do about it, other that what I and programering suggested.

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!