Criperum's picture

[Solved] InvalidValue from GL.ShaderSource

I have a shader generating procedure. The code is stored in simple string field. Then I use that simple code

Handler = GL.CreateShader(Type);
            if (Handler == 0)
                return Handler;
 
            //Set Source
            GL.ShaderSource(Handler, _code);
            var error = GL.GetError();

One of my generated shaders causes error variable equal to InvalidValue after calling GetError. As you can see handler is created just before code setting and _code field contains 100% correct code.

Can anyone help me with this issue?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Can you test with one of the other GL.ShaderSource() overloads that takes 4 parameters?

It would also help if you could upload the failing shader somewhere (preferrably as a txt file, in order to preserve its contents.)

Criperum's picture

Thank you for respond.

Testing other overrides failed too.

And here is the shader code:

#version 330 core
void norm(void);
void proj(void);
void main(){
norm();
proj();
}

next CreateShader call returns the same value as for the failed shader and it works fine.

the Fiddler's picture

Ok, one more test. Try using:

int Handler;
GL.CreateShader(Type, out Handler);

Does it work now?

Criperum's picture

I don't have the method in my version of OpenTK.

the Fiddler's picture

My mistake, you are right.

Is this Windows 64bit? Which version of .Net are you using?

I will try to reproduce the issue.

Criperum's picture

Win7 x64, .NET 4.5

Criperum's picture

I don't know if it could be usefull but when I looked through all Shader Creation moments I've noticed that Handlers are quite sequential:

1,2,3,4,5,6,8(and that handler causes failure)
As you can see there is no 7.

the Fiddler's picture

This smells like a driver issue to me. Are you using multiple OpenGL contexts?

I would suggest using apitrace to trace what is really going on here.

Criperum's picture

Thank you for the link. The problem was in wrong Attribute location binding. I was tring to bind it before program created.

I must be carefull refactoring my code.

the Fiddler's picture

Glad you solved it.

You can catch such errors sooner if you test with a debug version of OpenTK.dll (simply use OpenTK.sln to build the dll in debug mode.) The debug version will throw an exception as soon as an OpenGL error is an encountered.