Commit d40d683b authored by Christopher Tenter's avatar Christopher Tenter
Browse files

fixed memleak and possible crash in TextureNode refs #2218

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18863 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4d213f45
......@@ -259,38 +259,37 @@ void TextureNode::setTextureDataGL ( GLuint _textureId,
/** \brief Generate mipmaps for each texture that does not have one yet
*/
void TextureNode::updateMipmaps(bool _mipmap) {
// Make sure we have at least on element in the textures list
checkEmpty();
for(unsigned int i = 1; i < textures_.size(); ++i) {
// Bind texture
ACG::GLState::bindTexture( GL_TEXTURE_2D, textures_[i].id );
// Get pixel data out of texture memory
GLubyte* buffer = (GLubyte *)malloc(textures_[i].width*textures_[i].height*4);
glGetTexImage(textures_[i].target, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
if(_mipmap) {
// Build mipmap
gluBuild2DMipmaps(textures_[i].target, GL_RGBA, textures_[i].width, textures_[i].height,
GL_RGBA, GL_UNSIGNED_BYTE, buffer);
// Set mipmap available flag
textures_[i].mipmapAvailable = true;
} else {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textures_[i].width, textures_[i].height,
0, GL_RGBA, GL_UNSIGNED_BYTE, buffer );
// Set mipmap available flag
textures_[i].mipmapAvailable = false;
}
// Update parameters such that changes apply during runtime
applyTextureParameters(i);
// Make sure we have at least on element in the textures list
checkEmpty();
for(unsigned int i = 1; i < textures_.size(); ++i) {
// Bind texture
ACG::GLState::bindTexture( GL_TEXTURE_2D, textures_[i].id );
// size in bytes of level 0 texture
size_t bufferSize = textures_[i].width*textures_[i].height*4;
if(_mipmap && bufferSize) {
// Get pixel data out of texture memory
GLubyte* buffer = new GLubyte[bufferSize];
glGetTexImage(textures_[i].target, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
// Build mipmap
gluBuild2DMipmaps(textures_[i].target, GL_RGBA, textures_[i].width, textures_[i].height,
GL_RGBA, GL_UNSIGNED_BYTE, buffer);
delete [] buffer;
}
// Set mipmap available flag
textures_[i].mipmapAvailable = _mipmap;
// Update parameters such that changes apply during runtime
applyTextureParameters(i);
}
}
//----------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment