Little OT: Loading shader source from file "pre-mature eof"

Like i said in the subject, this is more C / C++ than OpenGL Shading Language, but i don´t know where i could ask else.
This is i feel like after debugging my code for 3 days and not getting a result:

  • :mad: :mad: :mad: -
    The problem is: Since i switched from the 3d-Labs-Shaderloadcode to my own :
 
ifstream file(key.c_str());
		if(!file.is_open()) 
			throw string (string("Could not find shaderfile: ") + key);
		for (string line; getline(file, line);) 
		{
			if (line != "FragmentShader") 
				vertex_shader_source.append(line);
			else 
				break;
		}
		for (string line; getline(file, line);	fragment_shader_source.append(line));
		const GLcharARB * VSS = vertex_shader_source.c_str();
		const GLcharARB * FSS = fragment_shader_source.c_str();
		glShaderSourceARB(VS, 1, &VSS, NULL);
		glShaderSourceARB(FS, 1, &FSS, NULL);
 

i get the following compilation error on my Radeon 9800 Pro
“pre-mature eof”
when i load one file as a vertex shader error.
With another file i get same error as a fragment-shader error.
And with a very short and simple shaderfile, there is no error at all.
I tried to erase all tabulators, enters and whitespaces of the shadercode, i tried to add them, i tried to write the code in different editors, i tried to add a “\0” to the strings, i tried to add or substract the last character of the strings, i tried to provide glShaderSourceARB the size of the strings and then to substract last char of the strings, etc. …
i also looked at the char * - strings in the debugger and at my console window, and couldn´t see any curious symbol.
Now i havn´t the slightest point what i do wrong.
I really hope someone (C/C++ expert?) can help me.

I think you simply forgot the last “}” in the shader, or somehow your code cuts your string too early in the end so you lose it.

You were right.
I found out what it was, with dropping more and more lines of code out of the shader, and saw that it worked, when the commentar was out. And this is after you’re explanation simply to understand: it commented the whole following shader out :rolleyes:
I fixed it with adding a ’
’ after each line.
:cool: :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.