i currently trying to get my model loader to work and got a error when binding new shader attributes.
At this point i would post the error message, but MonoTouch don’t let me do this. The only thing i got is “WARNING: Could n”, seems to be a issue with MonoTouch, because i used a template of the framework.
Here is the shader code:
<Shader>
<Uniforms>
<Uniform type="mat4" name="modelViewMatrix"/>
</Uniforms>
<Vertex>
<Attributes>
<Attribute type="vec3" name="position" binding="Position"/>
<Attribute type="vec3" name="normal" binding="Normals"/>
<!--<Attribute type="vec4" name="color" binding="Color"/>-->
</Attributes>
<Code><![CDATA[
attribute vec3 position;
attribute vec3 normal;
varying vec4 colorVarying;
uniform mat4 modelViewMatrix;
void main()
{
gl_Position = modelViewMatrix * vec4(position.xyz, 1.0);
float z = gl_Position.z / 100.0;
colorVarying = vec4(z, z, z, 1.0) ;
}
]]></Code>
</Vertex>
<Pixel>
<Code><![CDATA[
varying lowp vec4 colorVarying;
void main()
{
gl_FragColor = colorVarying;
}
]]></Code>
</Pixel>
</Shader>
The shader works perfectly when removing the “normal” attribute. When adding it i got the following error from mono ( Not from OpenGL ) after calling GL.LinkProgram:
App(553,0xacb752c0) malloc: *** error for object 0x1025a3c4: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
I noticed that it has something to do with the attribute binding. Here is the code:
// Bind attribute locations
for (int i = 0; i < _VertexAttributeList.Length; i++)
{
ShaderAttribute attribute = _VertexAttributeList[i];
GL.BindAttribLocation(_Program, i, attribute.Name);
}
When i replace “_VertexAttributeList.Length” with the constant 1 it works without any errors.
Cheers
Felix
I found the error after using the following lines of code:
It turns out that GLSL Ignores unused attributes and the attribute “normal” has a location of -1.
It has been a very annoying error, because of the fact that i know now what the error message means which i could not read because of the MonoTouch error: “Variable not used and ignored”.