[b]OS…Linux/Fedora 11 x64
Compiler…GCC 4.1.2
GL Version…2.1.2 NVIDIA 173.14.12
Issue: glCompileShader() call throws glibc detected error, specifically - free(): invalid next size(fast): followed by a 64-bit address.[/b]
Hello all. Bit of an odd problem here that I’m not sure how to go about resolving it - especially given that the issue wasn’t always there. This isn’t code that I wrote, but up until a couple of days ago it was working just fine.
There’s a function InitializeShaders() which does the standard glCreateShader, glShaderSource, glCompileShader routine for the vertex shader and the fragment shader.
Goes a bit like this:
void InitializeShaders()
{
/////////////////////////////////
//
// Create our vertex shader...
//
/////////////////////////////////
const char *vertexShaderStrings[1];
GLint bVertCompiled = false;
m_VertexShader = glCreateShader(GL_VERTEX_SHADER);
std::string vertexShaderFilename = "/shaders/vert_shader.vert";
// ReadShaderFile() returns the contents of the file as a cstring
unsigned char *vertexShaderAssembly = ReadShaderFile( vertexShaderFilename.c_str() );
vertexShaderStrings[0] = (char*)vertexShaderAssembly;
glShaderSource(m_VertexShader, 1, vertexShaderStrings, NULL);
glCompileShader( m_VertexShader ); // works okay here!
delete vertexShaderAssembly;
// Did it compile okay?
glGetShaderiv(m_VertexShader, GL_COMPILE_STATUS, &bVertCompiled);
if( bVertCompiled == false )
{
PrintShaderInfoLog(m_VertexShader);
}
//////////////////////////////////////
//
// Create our fragment shader...
//
//////////////////////////////////////
const char *fragmentShaderStrings[1];
GLint bFragCompiled = false;
m_FragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
std::string fragShaderFilename = "/shaders/frag_shader.frag";
unsigned char *fragmentShaderAssembly = ReadShaderFile( fragShaderFilename.c_str() );
fragmentShaderStrings[0] = (char*)fragmentShaderAssembly;
glShaderSource(m_FragmentShader, 1, fragmentShaderStrings, NULL);
glCompileShader( m_FragmentShader ); // CRASH CRASH CRASH
delete fragmentShaderAssembly;
// Did it compile okay?
glGetShaderiv(m_FragmentShader, GL_COMPILE_STATUS, &bFragCompiled);
if( bFragCompiled == false )
{
PrintShaderInfoLog(m_FragmentShader);
}
/////////////////////////////////
//
// Create a program object and attach our compiled shaders to it...
//
/////////////////////////////////
GLint bLinked = false;
m_ShaderProgram = glCreateProgram();
glAttachShader( m_ShaderProgram, m_VertexShader );
glAttachShader( m_ShaderProgram, m_FragmentShader );
//
// Link the program object and print out the info log...
//
glLinkProgram( m_ShaderProgram );
glGetProgramiv(m_ShaderProgram, GL_LINK_STATUS, &bLinked);
if( bLinked == false )
{
PrintProgramInfoLog( m_ShaderProgram );
}
}
I’ve narrowed it down to being the second glCompileShader through liberal use of cout and cout.flush… it’s definitely breaking somewhere in that glCompile call. I can’t understand what would cause a failed free() call in the shader, though, given there are no pointers or arrays of any kind being used in the shader. I’m not sure I can post the shader code for proprietariness (new word!) reasons, but… if anyone can suggest something to look for…?
The only parts of the code that have been touched are way deeper in the code where I experimented with changing a couple of variables LONG after glCompileShader has been called. I only commented them and changed a 1.0 to a 0.0, and have since changed them back, so I’m very very very hesitant to think this is the cause.
I’d think maybe libc or something had been updated, but this machine isn’t network connected so it has no way to pull updates…
EDIT: I’ve also cout’ed and verified that the shaders ARE being copied in correctly to the shaderAssembly/shaderStrings variables… and like I said, no pointer use in the shaders, so I don’t know where a free() call would be happening…