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(()) } }