@@ -17,7 +17,6 @@ extern crate glutin;
1717
1818use gl:: types:: * ;
1919use std:: ffi:: CString ;
20- use std:: mem;
2120use std:: ptr;
2221use std:: str;
2322
@@ -57,20 +56,19 @@ fn compile_shader(src: &str, ty: GLenum) -> GLuint {
5756 // Fail on error
5857 if status != ( gl:: TRUE as GLint ) {
5958 let mut len = 0 ;
59+ let mut outlen = 0 ;
6060 gl:: GetShaderiv ( shader, gl:: INFO_LOG_LENGTH , & mut len) ;
6161 let mut buf = Vec :: with_capacity ( len as usize ) ;
62- buf. set_len ( ( len as usize ) - 1 ) ; // subtract 1 to skip the trailing null character
6362 gl:: GetShaderInfoLog (
6463 shader,
6564 len,
66- ptr :: null_mut ( ) ,
65+ & mut outlen , // Number of characters written excluding null terminator
6766 buf. as_mut_ptr ( ) as * mut GLchar ,
6867 ) ;
68+ buf. set_len ( outlen as usize ) ;
6969 panic ! (
7070 "{}" ,
71- str :: from_utf8( & buf)
72- . ok( )
73- . expect( "ShaderInfoLog not valid utf8" )
71+ str :: from_utf8( & buf) . expect( "ShaderInfoLog not valid utf8" )
7472 ) ;
7573 }
7674 }
@@ -89,21 +87,20 @@ fn link_program(vs: GLuint, fs: GLuint) -> GLuint {
8987
9088 // Fail on error
9189 if status != ( gl:: TRUE as GLint ) {
92- let mut len: GLint = 0 ;
90+ let mut len = 0 ;
91+ let mut outlen = 0 ;
9392 gl:: GetProgramiv ( program, gl:: INFO_LOG_LENGTH , & mut len) ;
9493 let mut buf = Vec :: with_capacity ( len as usize ) ;
95- buf. set_len ( ( len as usize ) - 1 ) ; // subtract 1 to skip the trailing null character
9694 gl:: GetProgramInfoLog (
9795 program,
9896 len,
99- ptr :: null_mut ( ) ,
97+ & mut outlen , // Number of characters written excluding null terminator
10098 buf. as_mut_ptr ( ) as * mut GLchar ,
10199 ) ;
100+ buf. set_len ( outlen as usize ) ;
102101 panic ! (
103102 "{}" ,
104- str :: from_utf8( & buf)
105- . ok( )
106- . expect( "ProgramInfoLog not valid utf8" )
103+ str :: from_utf8( & buf) . expect( "ProgramInfoLog not valid utf8" )
107104 ) ;
108105 }
109106 program
@@ -141,8 +138,8 @@ fn main() {
141138 gl:: BindBuffer ( gl:: ARRAY_BUFFER , vbo) ;
142139 gl:: BufferData (
143140 gl:: ARRAY_BUFFER ,
144- ( VERTEX_DATA . len ( ) * mem :: size_of :: < GLfloat > ( ) ) as GLsizeiptr ,
145- mem :: transmute ( & VERTEX_DATA [ 0 ] ) ,
141+ size_of_val ( & VERTEX_DATA ) as GLsizeiptr ,
142+ VERTEX_DATA . as_ptr ( ) . cast ( ) ,
146143 gl:: STATIC_DRAW ,
147144 ) ;
148145
@@ -169,16 +166,18 @@ fn main() {
169166 * control_flow = ControlFlow :: Wait ;
170167 match event {
171168 Event :: LoopDestroyed => ( ) ,
172- Event :: WindowEvent { event, .. } => if event == WindowEvent :: CloseRequested {
173- // Cleanup
174- unsafe {
175- gl:: DeleteProgram ( program) ;
176- gl:: DeleteShader ( fs) ;
177- gl:: DeleteShader ( vs) ;
178- gl:: DeleteBuffers ( 1 , & vbo) ;
179- gl:: DeleteVertexArrays ( 1 , & vao) ;
169+ Event :: WindowEvent { event, .. } => {
170+ if event == WindowEvent :: CloseRequested {
171+ // Cleanup
172+ unsafe {
173+ gl:: DeleteProgram ( program) ;
174+ gl:: DeleteShader ( fs) ;
175+ gl:: DeleteShader ( vs) ;
176+ gl:: DeleteBuffers ( 1 , & vbo) ;
177+ gl:: DeleteVertexArrays ( 1 , & vao) ;
178+ }
179+ * control_flow = ControlFlow :: Exit
180180 }
181- * control_flow = ControlFlow :: Exit
182181 } ,
183182 Event :: RedrawRequested ( _) => {
184183 unsafe {
0 commit comments