From 1fd5aa627b97707d1dea7b1e57ea048f4442cfd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 26 Sep 2016 09:55:54 +0200 Subject: [PATCH] osmesa: Properly unbind the context. --- src/platform/with_osmesa/mod.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/platform/with_osmesa/mod.rs b/src/platform/with_osmesa/mod.rs index 81b6d31..bf8bc2b 100644 --- a/src/platform/with_osmesa/mod.rs +++ b/src/platform/with_osmesa/mod.rs @@ -98,8 +98,22 @@ impl NativeGLContextMethods for OSMesaContext { } fn unbind(&self) -> Result<(), &'static str> { - // OSMesa doesn't allow any API to unbind a context, and just bails out - // on null context, buffer, or whatever, so not much we can do here. + // OSMesa doesn't allow any API to unbind a context before [1], and just + // bails out on null context, buffer, or whatever, so not much we can do + // here. Thus, ignore the failure and just flush the context if we're + // using an old OSMesa version. + // + // [1]: https://www.mail-archive.com/mesa-dev@lists.freedesktop.org/msg128408.html + if self.is_current() { + let ret = unsafe { + osmesa_sys::OSMesaMakeCurrent(ptr::null_mut(), + ptr::null_mut(), 0, 0, 0) + }; + if ret == gl::FALSE { + gl::flush(); + } + } + Ok(()) } }