2011-10-28 70 views
1

我当前正试图让我的模型加载器工作并在绑定新的着色器属性时出错。OpenGL ES 2.0/MonoTouch:链接器错误

在这一点上,我会发布错误消息,但MonoTouch不要让我这样做。我唯一得到的是“警告:可以n”,似乎是MonoTouch的一个问题,因为我使用了框架模板。

这里是shader代码:删除 “正常” 的属性时

<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> 

的着色器完美的作品。当加入它,我打电话GL.LinkProgram后得到了单下面的错误(而不是从OpenGL的):

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 

我注意到,它是与属性结合。这里是代码:

// Bind attribute locations 
for (int i = 0; i < _VertexAttributeList.Length; i++) 
{ 
    ShaderAttribute attribute = _VertexAttributeList[i]; 
    GL.BindAttribLocation(_Program, i, attribute.Name); 
} 

当我用常数1替换“_VertexAttributeList.Length”它没有任何错误。

干杯 菲利克斯

+0

我们需要更多的细节。那是一个链接器错误?它在构建过程中失败(如果这样复制/粘贴)“构建输出”。如果额外的数据/解释太大而不适合这里,请填写bugzilla.xamarin.com上的错误报告并附上一个简单的测试用例。 – poupou

+0

错误postet不是链接器错误(malloc)。这是mono-develop的调试输出,并在调用Gl.LinkProgram后发生。在构建时也没有错误。 链接器错误是“警告:可能n”,并且由于单声道错误而未完成。 –

回答

2

我发现错误使用的下列代码行后:

for (int i = 0; i < _VertexAttributeList.Length) { 
    ShaderAttribute attribute = _VertexAttributeList[i]; 
    Console.WriteLine("Attribute {0} @ {1}", attribute.Name, 
         GL.GetAttribLocation(_Program, attribute.Name)); 
} 

事实证明,GLSL忽略未使用的属性和属性“正常”具有的位置-1 。

这是一个非常恼人的错误,因为我现在知道错误信息意味着我无法阅读,因为MonoTouch错误:“变量未被使用和忽略”。