2011-10-28 68 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錯誤:「變量未被使用和忽略」。