title: OpenGl Shader Program Linking error with uncertain reason
body: <p>I'm trying to make a framework that uses OpenGL.</p>
  
  <p>Yet, having problem to reload shader program.</p>
  
  <p><img src="https://i.stack.imgur.com/qOrdQ.png" alt="Succeeds to link"></p>
  
  <p>This is what I have right now.</p>
  
  <p>I load and compile a vertex shader and a fragment shader(both contain main).</p>
  
  <p>Than I link a program with them.</p>
  
  <p>At first, it has no problem. No matter how much time I refresh shaders.
  (If I press Refresh Shader, the application creates new shader, program resource and replaces original ones with them)</p>
  
  <p>Than, if I load a mesh and preform some drawing calls(using VBO), This time Refresh Shader Fails with following message.</p>
  
  <p><img src="https://i.stack.imgur.com/tnTnM.png" alt="Fails to link"></p>
  
  <p>I have no idea how my draw calls or VBO function calls could possibly be related to Shader Linking...</p>
  
  <p>I'm not even sure if that is the exact reason or not.</p>
  
  <p>Shader class:</p>
  
  <pre><code>  class Shader : public Named
    {
  
      // -------------------------------------------------------
      // --------------- Defs ----------------------------------
    public:
      typedef void (*ErrFunc)( Shader* pShader, const char* const errMsg );
  
  
  
      // -------------------------------------------------------
      // --------------- Funcs ---------------------------------
    public:
  
      //
      // Shader Controls
      //
      // pre: source is string contains source
      Shader( const std::string&amp; name, GLenum type);
  
      ~Shader( void );
  
      // pre: file to loast source. Give nullptr to load from lastly loaded file
      void ShaderSourceFromFile( const char* file );
  
      void ShaderSource( const std::string&amp; source );
  
      void Compile( void );
  
      void AttachTo( GLuint program );
  
      void DetachFrom( GLuint program );
  
      GLuint GetId( void );
  
      void SetId( GLuint shaderId );
  
      GLint GetType( void );
  
      GLint GetCompileStatus( void );
  
      const char* const GetShaderInfoLog( void );
  
  
      //
      // Err Control
      //
    public:
  
      void Error ( const char* pErrMsg );
  
      static ErrFunc SetErrFunc( ErrFunc fpNewErrFunc );
  
  
      // -------------------------------------------------------
      // ----------- Vars --------------------------------------
    private:
      // id of the shader
      GLuint  _shaderId;
  
      // type of the shader
      GLenum  _type;
  
      // error func
      static ErrFunc s_fpErrFunc;
  
  
  
  
  
    }; // class Shader
  
    //
    // Shader
    //
  
    Shader::ErrFunc Shader::s_fpErrFunc = nullptr;
  
  
    Shader::Shader( const std::string&amp; name, GLenum type) :
      Named(name),
      _shaderId(GL_INVALID_RESOURCE_ID),
      _type(type)
    {
      // Create shader
      GLint id = glCreateShader(type);
  
      // Failed to create shader?
      if ( id == GL_INVALID_RESOURCE_ID )
        Error("(Shader::Shader) Failed to create shader resource");
  
      // Set shader id
      SetId(id);
  
    }
  
    Shader::~Shader( void )
    {
      // Delete shader
      glDeleteShader(GetId());
  
      // Error Check
      if( glGetError() == GL_INVALID_VALUE )
        Error("(Shader::~Shader) given id to delete was not shader");
    }
  
    void Shader::Compile( void )
    {
      // Compile shader
      glCompileShader(_shaderId);
  
      switch( glGetError() )
      {
      case GL_NO_ERROR:break;
      case GL_INVALID_VALUE:     Error("shader is not a value generated by OpenGL.");break;
      case GL_INVALID_OPERATION: Error("shader is not a shader object.");break;
      default:Error("Unkown Error");
      }
      // ErrorCheck
      if( GetCompileStatus() == GL_FALSE )
        Error("(Shader::Compile) Compilation Failed.");
  
    }
  
    void Shader::ShaderSourceFromFile( const char* file  )
    {
        ShaderSource(ReadEntireFile(file));
    }
    // pre: source is string contains source
    void Shader::ShaderSource( const std::string&amp; source )
    {
      const GLchar* pSource = source.c_str();
      glShaderSource( GetId(),  // shader id
                      1,        // count of source. only one at a time at the moment
                      &amp;pSource, // buffer that source is stored
                      nullptr); // length is not specified, yet null terminated
      switch( glGetError() )
      {
      case GL_NO_ERROR:
        break;
      case GL_INVALID_VALUE:
        Error("invalid shader or bufsize is less than 0");
        break;
      case GL_INVALID_OPERATION:  
        Error("shader is not a shader object."); 
        break;
      default:
        Error("Unkown Error");
        break;
      }
    }
    void Shader::AttachTo( GLuint program )
    {
      glAttachShader(program, GetId());
  
      if( glGetError() != GL_NO_ERROR )
      {
        Error("(Shader::AttachTo) Error Happend Performing glAttachShader");
      }
    }
  
    void Shader::DetachFrom( GLuint program )
    {
      glDetachShader(program, GetId());
  
      switch( glGetError() )
      {
      case GL_NO_ERROR:
        break;
      case GL_INVALID_VALUE:
        Error("(Shader::DetachFrom)either program or shader is a value that was not generated by OpenGL.");
        break;
      case GL_INVALID_OPERATION:
        Error("(Shader::DetachFrom)program is not a program object. or "
        "shader is not a shader object. or "
        "shader is not attached to program.");
        break;
      default:
        Error("(Shader::DetachFrom)Unkown Error");
          break;
      }
    }
  
    GLuint Shader::GetId( void )
    {
      return _shaderId;
    }
  
    void Shader::SetId( GLuint shaderId )
    {
      _shaderId = shaderId;
    }
  
    GLint Shader::GetType( void )
    {
      return _type;
    }
  
    void Shader::Error ( const char* pErrMsg )
    {
      if( s_fpErrFunc )
        s_fpErrFunc(this, pErrMsg);
    }
  
    Shader::ErrFunc Shader::SetErrFunc( ErrFunc fpNewErrFunc )
    {
      ErrFunc prev = s_fpErrFunc;
      s_fpErrFunc = fpNewErrFunc;
      return prev;
    }
  
    GLint Shader::GetCompileStatus( void )
    {
      GLint status;
      glGetShaderiv(GetId(), GL_COMPILE_STATUS, &amp;status );
      GLint err = glGetError();
      switch( err )
      {
      case GL_NO_ERROR:
        break;
      case GL_INVALID_ENUM:
        Error("(Shader::GetCompileStatus) Invalid Enum passed to glGetShaderiv");
        break;
      case GL_INVALID_VALUE:
        Error("(Shader::GetCompileStatus) Invalid Shader id passed to glGetShaderiv");
        break;
      case GL_INVALID_OPERATION:
        Error("(Shader::GetCompileStatus) Invalid Shader id or shader does not support");
        break;
      default:
        Error("(Shader::GetCompileStatus) Unkown Error");
        break;
  
      }
      return status;
    }
    const char* const Shader::GetShaderInfoLog( void )
    {
      static const unsigned s_bufSize = 0x1000;
      static GLchar s_buf[s_bufSize] = {0};
  
      // Get InfoLog
      glGetShaderInfoLog(GetId(), s_bufSize, nullptr, s_buf);
  
      // Error Check
      if( glGetError() != GL_NO_ERROR )
        Error("(Shader::GetCompileStatus) There was Error performing glGetShaderInfoLog");
  
      // return buffer
      return s_buf;
    }
  </code></pre>
  
  <p>Refreshing Function:</p>
  
  <pre><code> void GLShaderManager::Refresh( void )
    {
  
  
  
    // Gets current shader
    Shader* pVertexPrev = _shaderMap["Vertex"];
    Shader* pFragPrev = _shaderMap["Fragment"];
  
  
    // Delete them(glDeleteShader call is included)
    if( pVertexPrev &amp;&amp; pFragPrev )
    {
      delete pVertexPrev;
      delete pFragPrev;
    }
  
  
    // Loads shader
    LoadShader("Vertex", GL_VERTEX_SHADER, s_vertexFile);
    LoadShader("Fragment", GL_FRAGMENT_SHADER, s_fragmentFile);
  
    // Delete Current Program
    glDeleteProgram(_program);
  
    // Create new Program
    GLuint newProgram = glCreateProgram();
    _program = newProgram;
  
    // Attach Shaders
    UseShader("Vertex");
    UseShader("Fragment");
  
    // Linking
    glLinkProgram(_program);
    const unsigned bufSize = 0x1000;
    char buf[bufSize] = { '\0' };
    GLint status = 0;
    glGetProgramiv(_program, GL_LINK_STATUS, &amp;status );
    if( status )
      Gui::Get().Output("Shader program linked successfully.");
    glGetProgramInfoLog(_program, bufSize, nullptr, buf);
    Gui::Get().Output(buf);
  
  
    s_uniformErrHistory.clear();
  }
  
  void GLShaderManager::LoadShader( const std::string&amp; name, GLenum type, const std::string&amp; sourceFile )
      {
        Shader* pShader = _shaderMap[name] = new Shader(name, type);
        if( pShader )
        {
          pShader-&gt;ShaderSourceFromFile(sourceFile.c_str());
          pShader-&gt;Compile();
          if( pShader-&gt;GetCompileStatus() )
            Gui::Get().Output( (pShader-&gt;GetName() + " shader successfully compiled.").c_str());
          Gui::Get().Output(pShader-&gt;GetShaderInfoLog());
        }
      }
      void GLShaderManager::UseShader( const std::string&amp; name )
      {
        Shader* pShader = _shaderMap[name];
        if( pShader )
        {
            pShader-&gt;AttachTo(_program);
        }
      }
  </code></pre>