PDA

View Full Version : Debugger Fails to Start, glbindTexture() causes Heap block modified after it was free



mlegako
10-15-2014, 10:55 AM
I have a Qt/OpenGl application I am working on that has been running for some time. It produces data based waterfalls; an X-Y-C plot that animates by moving the data down the screen. Of course my original program was merely a test application, and now I'm adding an Ethernet Interface to it so that the source of the data being plotted can originate from a different machine. I'm using Qt 5.2.0 with OpenGL support, MSVC 2012, on a Windows 7 64 bit machine. (The application also runs under Red Hat Linux, and several other variations). After updating the application with some new code that switched the application to use manual layouts and added a status bar with a number of controls, I now get a rather strange error when the application begins that doesn't appear related to any of these things, but is instead part of the OpenGl code.

I should also say, I'm not having any luck running the debugger from within Qt Creator. When I attempt this, I get only the following messages:

Debugging starts
Debugging has finished (almost immediately)

And no other indication of what might be wrong.

If I run the application using the MSVS2012 IDE to start the Debugger, I get the error:
HEAP[App_Waterfall_Observer.exe]: HEAP: Free Heap block 48a9920 modified at 48a9a5c after it was freed

The line at which the code breaks is within a function I use to update my textures (shown below with breakpoint line highlighted). I think the failure is occurring on 1st entry of this function with the 'texture' variable set to a deliberately invalid code: 0xffffffff, and the ptr variable pointing to an RGBA 8 8 8 8 REV image previously created in memory, its dimensions in bsize with bsize[0]=width, and bsize[1]=length. The code is designed to reuse textures as often as possible (they never change size once they are created, but their data changes every second), so this function is designed to update them with new data as well as create them in the 1st place. InterpretGLError() is a member function that just uses printf() to output the error to the console so I can find it. No error messages are generated previous to the Heap issue.

QUESTIONS:
(1) Does anybody know how to diagnose why the debugger won't start from with Qt Creator?
(2) Does anybody see anything in the way I'm creating the 1st texture that might account for the Heap modification issue?

Thanks, for reading this!

GLuint TextureMgr::UpdateTexture(unsigned char *ptr,GLuint texture,size_t bsize[2])
{
int ierrcode=GL_NO_ERROR;
GLint width,height;
if(glIsTexture(texture))
{
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTUR E_WIDTH,&width);
glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTUR E_HEIGHT,&height);
if(((int)bsize[0]!=width)||
((int)bsize[1]!=height))
{
glDeleteTextures(1,&texture);
if((ierrcode=glGetError())!=GL_NO_ERROR)
InterpretGLError(ierrcode,__FUNCTION__,__LINE__);
}
}
if(!glIsTexture(texture))
{

glGenTextures(1,&texture);
//printf("Generating texture=%d\n",texture);
if((ierrcode=glGetError())!=GL_NO_ERROR)
InterpretGLError(ierrcode,__FUNCTION__,__LINE__);
glBindTexture(GL_TEXTURE_2D,texture);
if((ierrcode=glGetError())!=GL_NO_ERROR)
InterpretGLError(ierrcode,__FUNCTION__,__LINE__);
//glPixelStorei(GL_UNPACK_ALIGNMENT,sizeof(unsigned long int));
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,(GLsizei)bsiz e[0],(GLsizei)bsize[1],0,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8_REV,ptr);
if((ierrcode=glGetError())!=GL_NO_ERROR)
InterpretGLError(ierrcode,__FUNCTION__,__LINE__);
}
else
{
// Use image as a texture
//printf("Reusing texture=%d\n",texture);
glBindTexture(GL_TEXTURE_2D,texture);
if((ierrcode=glGetError())!=GL_NO_ERROR)
InterpretGLError(ierrcode,__FUNCTION__,__LINE__);

glTexSubImage2D(GL_TEXTURE_2D,0,0,0,(GLsizei)bsize[0],(GLsizei)bsize[1],GL_RGBA,GL_UNSIGNED_INT_8_8_8_8_REV,ptr);
if((ierrcode=glGetError())!=GL_NO_ERROR)
InterpretGLError(ierrcode,__FUNCTION__,__LINE__);
}
//texture = bindTexture(Q);
glEnable(GL_TEXTURE_2D);
if((ierrcode=glGetError())!=GL_NO_ERROR)
InterpretGLError(ierrcode,__FUNCTION__,__LINE__);
// Set nearest filtering mode for texture minification
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
if((ierrcode=glGetError())!=GL_NO_ERROR)
InterpretGLError(ierrcode,__FUNCTION__,__LINE__);
// Set bilinear filtering mode for texture magnification
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if((ierrcode=glGetError())!=GL_NO_ERROR)
InterpretGLError(ierrcode,__FUNCTION__,__LINE__);
// Wrap texture coordinates by repeating
// f.ex. texture coordinate (1.1, 1.2) is same as (0.1, 0.2)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
if((ierrcode=glGetError())!=GL_NO_ERROR)
InterpretGLError(ierrcode,__FUNCTION__,__LINE__);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
if((ierrcode=glGetError())!=GL_NO_ERROR)
InterpretGLError(ierrcode,__FUNCTION__,__LINE__);
return(texture);
}