aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Krieger <pierre.krieger1708@gmail.com>2014-11-14 15:59:45 +0100
committerPierre Krieger <pierre.krieger1708@gmail.com>2014-11-14 15:59:45 +0100
commit9b39d99f6efa45bb6629f9f819c7e8589281e61e (patch)
tree6110047815943ce5a6008af25300d04c93366f5d
parent37bdb997cea05064ed6ad56f51fb2194e176a070 (diff)
downloadglutin-9b39d99f6efa45bb6629f9f819c7e8589281e61e.tar.gz
glutin-9b39d99f6efa45bb6629f9f819c7e8589281e61e.zip
Detect OSMesa errors
-rw-r--r--src/x11/headless.rs15
-rw-r--r--tests/headless.rs3
2 files changed, 13 insertions, 5 deletions
diff --git a/src/x11/headless.rs b/src/x11/headless.rs
index 71232e5..977305a 100644
--- a/src/x11/headless.rs
+++ b/src/x11/headless.rs
@@ -1,5 +1,5 @@
use HeadlessRendererBuilder;
-use CreationError;
+use {CreationError, OsError};
use libc;
use std::{mem, ptr};
use super::ffi;
@@ -18,16 +18,23 @@ impl HeadlessContext {
height: builder.dimensions.1,
buffer: Vec::from_elem(builder.dimensions.0 * builder.dimensions.1, unsafe { mem::uninitialized() }),
context: unsafe {
- // TODO: check errors
- ffi::OSMesaCreateContext(0x1908, ptr::null())
+ let ctxt = ffi::OSMesaCreateContext(0x1908, ptr::null());
+ if ctxt.is_null() {
+ return Err(OsError("OSMesaCreateContext failed".to_string()));
+ }
+ ctxt
}
})
}
pub unsafe fn make_current(&self) {
- ffi::OSMesaMakeCurrent(self.context,
+ let ret = ffi::OSMesaMakeCurrent(self.context,
self.buffer.as_ptr() as *mut libc::c_void,
0x1401, self.width as libc::c_int, self.height as libc::c_int);
+
+ if ret == 0 {
+ panic!("OSMesaMakeCurrent failed")
+ }
}
pub fn get_proc_address(&self, addr: &str) -> *const () {
diff --git a/tests/headless.rs b/tests/headless.rs
index fe82c1d..084f228 100644
--- a/tests/headless.rs
+++ b/tests/headless.rs
@@ -32,6 +32,7 @@ fn main() {
gl.ReadPixels(0, 0, 1, 1, gl::RGBA, gl::UNSIGNED_BYTE, std::mem::transmute(&mut value));
assert!(value == (0, 255, 0, 255) || value == (0, 64, 0, 255) ||
- value == (0, 64, 0, 255) || value == (0, 64, 0, 0));
+ value == (0, 64, 0, 255) || value == (0, 64, 0, 0),
+ "value is: {}", value);
}
}