C++ glShaderSource崩溃

C++ glShaderSource崩溃,c++,opengl,C++,Opengl,我使用: 然后应用程序就崩溃了 源变量还包含以下内容: std::string source; char value; std::ifstream stream(paths[id]); while (stream.get(value)) { source += value; } stream.close() int shader = glCreateShader(mode); shaders[id] = shader; glShaderSour

我使用:

然后应用程序就崩溃了 源变量还包含以下内容:

std::string source;
char value;
std::ifstream stream(paths[id]);
while (stream.get(value)) {

    source += value;
}
stream.close()

        
        
int shader = glCreateShader(mode);
shaders[id] = shader;


glShaderSource(shader, 1, (const GLchar* const *)source.c_str(), nullptr);

glCompileShader(shader);
应用程序崩溃了


问题出在哪里?

问题出在这里:
(const GLchar*const*)source.c_str()
。如果没有强制转换(实际上是一个
重新解释\u强制转换
),它就不能工作,这表明你做错了什么


将指针保存到变量:
const char*ptr=source.c_str()
,然后将
&ptr
传递给
glShaderSource

问题在这里:
(const GLchar*const*)source.c_str()
。如果没有强制转换(实际上是一个
重新解释\u强制转换
),它就不能工作,这表明你做错了什么

将指针保存到变量:
const char*ptr=source.c_str()
,然后将
&ptr
传递给
glShaderSource

问题就在这里

 #version 330 core
 layout(location = 0) in vec3 aPos;

void main()
{
    gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
试着这样做

glShaderSource(shader, 1, (const GLchar* const *)source.c_str(), nullptr);
问题就在这里

 #version 330 core
 layout(location = 0) in vec3 aPos;

void main()
{
    gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
试着这样做

glShaderSource(shader, 1, (const GLchar* const *)source.c_str(), nullptr);