David Szalai
David Szalai

Reputation: 2539

Shader data as char array - 0xFEEEFEEE error

I managed to remade my shader compiler so as not to use two or more .txt files, only one with #defines for the programs. Now it works well, but it behaves weird if I don't hit an enter or leave space after the last line of the shader.txt: I get the error mentioned in the title.

My shader loader:

m_vertexShader.source = readFile(m_vertexShader.filename);//.source is string
const GLchar defineVertex[]   = "#define VERTEX  \n";

const GLchar* vertexsource[2]={defineVertex,
              static_cast<const GLchar*>(m_vertexShader.source.c_str())};

glShaderSource(m_vertexShader.id, 2, vertexsource, NULL);

and the same for the fragment program.

The source reader:

string readFile(const string& filename)
{
    ifstream fileIn(filename.c_str());

    if (!fileIn.good())
    {
        std::cerr << "Could not load shader: " << filename << std::endl;
        return string();
    }

    string stringBuffer(std::istreambuf_iterator<char>(fileIn),(std::istreambuf_iterator<char>()));
    return stringBuffer;
}

Well, in the .txt I still have few lines:

#version 400
layout (location = 0)
in vec3 a_Vertex;
uniform mat4 model_matrix;
uniform mat4 view_matrix;
uniform mat4 projection_matrix;
mat4 mvp = projection_matrix*view_matrix*model_matrix;
#ifdef VERTEX
void main(void)
{
    gl_Position = mvp*vec4(a_Vertex,1);
}
#endif
#ifdef FRAGMENT void main(void)
{
    gl_FragColor = vec4(gl_FragCoord.zzz,1);
}
#endif

so if I left this in this form, and the last char is the "f" of #endif I get the message. What happens with it in this form, and what differs when there's space after the last character.

EDIT: I know what is the feeefeee error, but I dont know how a space could cause memory error.

Upvotes: 0

Views: 315

Answers (2)

user2802841
user2802841

Reputation: 913

It might be that your graphics card driver implementation of shader compiler expects shader source to end with white space character. This might come from empty line requirement at the end of a source file in C. I am not sure if GLSL standard requires this, but you probably should leave an empty line just to be safe.

EDIT:

While I couldn't find anything in GLSL spec that would require shader source to end with a new line or white space, because your shader ends with #endif this might be caused by preprocessor rule that states:

Each directive is terminated by a new line.

Upvotes: 2

Ivan Ishchenko
Ivan Ishchenko

Reputation: 1526

Every gl shader must end with \n. I've tried to find why in my time but I failed. But is a known bug/feature.

Upvotes: 1

Related Questions