Jump to content

  • Log In with Google      Sign In   
  • Create Account

Sagaceil

Member Since 04 May 2009
Offline Last Active Aug 24 2016 05:06 AM

#5251712 Error with shaders - OpenGL

Posted by on 11 September 2015 - 07:38 AM

try:


        std::string vertSourceString = FileUtils::read_file(m_VertPath);
        std::string fragSourceString = FileUtils::read_file(m_FragPath);

        const char* vertSource = vertSourceString.c_str();
        const char* fragSource = fragSourceString.c_str();

        glShaderSource(vertex, 1, &vertSource , NULL);




#5251678 Error with shaders - OpenGL

Posted by on 11 September 2015 - 01:05 AM


        const char* vertSource = FileUtils::read_file(m_VertPath).c_str();
        const char* fragSource = FileUtils::read_file(m_FragPath).c_str();

 

It seems like strings are created from function, then you getting c_str of them. Now strings are destroyed, but pointers are still in use. Try to do something like:

const std::string vertSource = FileUtils::read_file(m_VertPath);
const std::string fragSource = FileUtils::read_file(m_FragPath); 

// ... 

glShaderSource(vertex, 1, &vertSource.c_str(), NULL); // same for fragment

// ... 

This way, strings are remaninbg for whole function scope and keeps valid c_str pointers.




PARTNERS