Unknown error 0x0502

This is the program that renders an object with several lighting techniques.

/*
first operation : mesh.render(prog)
*/                                                    
mesh.render( prog );

/* render function*/

virtual void render( const Program& program, const mat4& modelMat_=mat4(1) ) {
	
    if( !visible ) return;
	
	if( vBuf<1 || eBuf<1 || dataDirty ) {
		if( data.verts.size()<1 ) {
			clear();
			return;
		}
		else createMeshGL();
		glErr("Create MeshGL");
	}
	glBindVertexArray( vao );
	program.setUniform("modelMat", modelMat_*modelMat );
	glErr("set uniform modelMat");
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, eBuf);
	glErr("bind element array buffer");
	glDrawElements(GL_TRIANGLES, nTris*3, GL_UNSIGNED_INT, 0);
	glErr("Draw elements");
	
	glBindVertexArray( 0 );
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
	glBindBuffer( GL_ARRAY_BUFFER, 0 );
}

/*create mesh gl*/

virtual void createMeshGL() {	

	if( data.tris.size() == nTris && data.verts.size() == nVerts && vao>0 && eBuf>0 ) {
		printf("Updating mesh\n");
		glBindBuffer( GL_ARRAY_BUFFER, vBuf);
		glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(vec3) * nVerts, data.verts.data() );
		if( data.norms.size()>0 ) {
			glBindBuffer(GL_ARRAY_BUFFER, nBuf);
			glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vec3) * nVerts, data.norms.data() );
		}
		
		if( data.tcoords.size()>0 ) {
			glBindBuffer(GL_ARRAY_BUFFER, tBuf);
			glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vec2) * nVerts, data.tcoords.data() );
		}
		glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, eBuf);
		glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(uvec3) * nTris, data.tris.data()  );
	}
	else {
		if( vao ) glDeleteVertexArrays(1, &vao);
		if( vBuf ) glDeleteBuffers(1, &vBuf);
		if( nBuf ) glDeleteBuffers(1, &nBuf);
		if( tBuf ) glDeleteBuffers(1, &tBuf);
		if( eBuf ) glDeleteBuffers(1, &eBuf);
		nTris  = GLsizei(data.tris.size());
		nVerts = GLsizei(data.verts.size());
		
		glGenVertexArrays(1, &vao );
		glBindVertexArray( vao );
		
		glGenBuffers(1, &vBuf);
		glBindBuffer( GL_ARRAY_BUFFER, vBuf);
		glBufferData( GL_ARRAY_BUFFER, sizeof(vec3) * nVerts, data.verts.data(), GL_STATIC_DRAW );
		glEnableVertexAttribArray(0);
		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
		
		if( data.norms.size()>0 ) {
			glGenBuffers(1, &nBuf);
			glBindBuffer(GL_ARRAY_BUFFER, nBuf);
			glBufferData(GL_ARRAY_BUFFER, sizeof(vec3) * nVerts, data.norms.data(), GL_STATIC_DRAW);
			glEnableVertexAttribArray(1);
			glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
		}
		
		if( data.tcoords.size()>0 ) {
			glGenBuffers(1, &tBuf);
			glBindBuffer(GL_ARRAY_BUFFER, tBuf);
			glBufferData(GL_ARRAY_BUFFER, sizeof(vec2) * nVerts, data.tcoords.data(), GL_STATIC_DRAW);
			glEnableVertexAttribArray(2);
			glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
		}
		glGenBuffers(1, &eBuf);
		glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, eBuf);
		glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(uvec3) * nTris, data.tris.data(), GL_STATIC_DRAW );
		glBindVertexArray( 0 );
		
	}
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
	glBindBuffer( GL_ARRAY_BUFFER, 0 );
	data.clear();
	dataDirty = false;
}

/*
error function.
*/
inline void glErr( const std::string& message ) {
	GLint err = glGetError();
	const GLubyte* errString = glewGetErrorString(err);

	if( err != GL_NO_ERROR ) {
		std::cerr << "GLEW Error " << errString << std::endl;
		printf("%08X ", err );
		std::cerr<<"GL Error: "<<message<<std::endl;
	}
}

output :

GLEW Error Unknown error
00000502 GL Error: Create MeshGL

0x0502 is related to INVALID_OPERATION. but I’m not sure which is invalid in above code.
and I have tried with example code which works fine, it does not return any error.

My Quesiton is, is there any component that has possibility of error in create mesh gl?

If you have OpenGL 4.3 or the KHR_debug extension, consider using glDebugMessageCallback. Otherwise, add more glErr calls to identify the specific command generating the error.

In createMeshGL, glBufferSubData, glBindVertexArray, glBufferData, glEnableVertexAttribArray, and glVertexAttribPointer can generate GL_INVALID_OPERATION errors. But it isn’t guaranteed that the error is being generated within that function, as the error flag may have already been set prior to entry.

More on this here:

The GL debug message facility often provides more details on the error thrown than just the basic error code. For example:

GL_INVALID_OPERATION error generated. State(s) are invalid: program texture usage.
GL_INVALID_OPERATION error generated. Texture name does not refer to a texture object generated by OpenGL.
GL_INVALID_OPERATION error generated. Wrong component type or count.
GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1

Additionally, if you’re using NVIDIA graphics drivers, consider also setting Threaded Optimization = OFF in the NVIDIA Control Panel. With this, that GL message callback will be called to alert you of the GL error literally while execution is inside the exact GL call you made that triggered the GL error. With this, you can walk the stack and examine your program’s state when your program triggers error, both to see where it was triggered and “why” it was triggered.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.