I use:
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);
And the app crashes on Also source varible contains exactly:
#version 330 core
layout(location = 0) in vec3 aPos;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
And the app just crashes!
What is the issue?
The problem is here:
(const GLchar* const *)source.c_str()
. The fact that it didn't work without a cast (effectively areinterpret_cast
) is a sign that you're doing something wrong.Save the pointer to a variable:
const char *ptr = source.c_str();
, then pass&ptr
toglShaderSource
.