mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-27 15:13:13 -04:00
Merge pull request #486 from tomaka/context-error
Handle errors from MakeCurrent and SwapBuffers
This commit is contained in:
@@ -15,6 +15,7 @@ use std::collections::VecDeque;
|
||||
|
||||
use Api;
|
||||
use BuilderAttribs;
|
||||
use ContextError;
|
||||
use CursorState;
|
||||
use GlContext;
|
||||
use GlRequest;
|
||||
@@ -213,7 +214,7 @@ unsafe impl Send for Window {}
|
||||
unsafe impl Sync for Window {}
|
||||
|
||||
impl GlContext for Window {
|
||||
unsafe fn make_current(&self) {
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
self.context.make_current()
|
||||
}
|
||||
|
||||
@@ -225,7 +226,7 @@ impl GlContext for Window {
|
||||
self.context.get_proc_address(addr)
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
self.context.swap_buffers()
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use api::osmesa::{OsMesaContext, OsMesaCreationError};
|
||||
|
||||
use Api;
|
||||
use BuilderAttribs;
|
||||
use ContextError;
|
||||
use CreationError;
|
||||
use Event;
|
||||
use GlContext;
|
||||
@@ -209,7 +210,7 @@ impl Window {
|
||||
}
|
||||
|
||||
impl GlContext for Window {
|
||||
unsafe fn make_current(&self) {
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
self.opengl.make_current()
|
||||
}
|
||||
|
||||
@@ -221,7 +222,7 @@ impl GlContext for Window {
|
||||
self.opengl.get_proc_address(addr)
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
unsafe {
|
||||
let canvas = (self.libcaca.caca_get_canvas)(self.display);
|
||||
let width = (self.libcaca.caca_get_canvas_width)(canvas);
|
||||
@@ -235,6 +236,8 @@ impl GlContext for Window {
|
||||
buffer.as_ptr() as *const _);
|
||||
(self.libcaca.caca_refresh_display)(self.display);
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_api(&self) -> Api {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use ContextError;
|
||||
use CreationError;
|
||||
use CreationError::OsError;
|
||||
use BuilderAttribs;
|
||||
@@ -61,7 +62,7 @@ impl HeadlessContext {
|
||||
}
|
||||
|
||||
impl GlContext for HeadlessContext {
|
||||
unsafe fn make_current(&self) {
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
self.context.makeCurrentContext();
|
||||
|
||||
gl::GenFramebuffersEXT(1, &mut framebuffer);
|
||||
@@ -78,6 +79,8 @@ impl GlContext for HeadlessContext {
|
||||
if status != gl::FRAMEBUFFER_COMPLETE_EXT {
|
||||
panic!("Error while creating the framebuffer");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_current(&self) -> bool {
|
||||
@@ -96,7 +99,8 @@ impl GlContext for HeadlessContext {
|
||||
symbol as *const libc::c_void
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_api(&self) -> ::Api {
|
||||
|
||||
@@ -8,6 +8,7 @@ use libc;
|
||||
|
||||
use Api;
|
||||
use BuilderAttribs;
|
||||
use ContextError;
|
||||
use GlContext;
|
||||
use GlProfile;
|
||||
use GlRequest;
|
||||
@@ -781,9 +782,10 @@ impl Window {
|
||||
}
|
||||
|
||||
impl GlContext for Window {
|
||||
unsafe fn make_current(&self) {
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
let _: () = msg_send![*self.context, update];
|
||||
self.context.makeCurrentContext();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_current(&self) -> bool {
|
||||
@@ -810,8 +812,9 @@ impl GlContext for Window {
|
||||
symbol as *const _
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
unsafe { self.context.flushBuffer(); }
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_api(&self) -> ::Api {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#![allow(unused_variables)]
|
||||
|
||||
use BuilderAttribs;
|
||||
use ContextError;
|
||||
use CreationError;
|
||||
use GlContext;
|
||||
use GlRequest;
|
||||
@@ -161,11 +162,18 @@ impl Context {
|
||||
}
|
||||
|
||||
impl GlContext for Context {
|
||||
unsafe fn make_current(&self) {
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
let ret = self.egl.MakeCurrent(self.display, self.surface, self.surface, self.context);
|
||||
|
||||
if ret == 0 {
|
||||
panic!("eglMakeCurrent failed");
|
||||
if self.egl.GetError() as u32 == ffi::egl::CONTEXT_LOST {
|
||||
return Err(ContextError::ContextLost);
|
||||
} else {
|
||||
panic!("eglMakeCurrent failed");
|
||||
}
|
||||
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,13 +189,20 @@ impl GlContext for Context {
|
||||
}
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
let ret = unsafe {
|
||||
self.egl.SwapBuffers(self.display, self.surface)
|
||||
};
|
||||
|
||||
if ret == 0 {
|
||||
panic!("eglSwapBuffers failed");
|
||||
if unsafe { self.egl.GetError() } as u32 == ffi::egl::CONTEXT_LOST {
|
||||
return Err(ContextError::ContextLost);
|
||||
} else {
|
||||
panic!("eglSwapBuffers failed");
|
||||
}
|
||||
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ use libc;
|
||||
use {Event, BuilderAttribs, CreationError, MouseCursor};
|
||||
use Api;
|
||||
use PixelFormat;
|
||||
use ContextError;
|
||||
use GlContext;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
@@ -191,9 +192,10 @@ impl Window {
|
||||
}
|
||||
|
||||
impl GlContext for Window {
|
||||
unsafe fn make_current(&self) {
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
// TOOD: check if == EMSCRIPTEN_RESULT
|
||||
ffi::emscripten_webgl_make_context_current(self.context);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_current(&self) -> bool {
|
||||
@@ -209,10 +211,9 @@ impl GlContext for Window {
|
||||
}
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
unsafe {
|
||||
ffi::emscripten_sleep(1); // FIXME:
|
||||
}
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
unsafe { ffi::emscripten_sleep(1); } // FIXME:
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_api(&self) -> Api {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#![cfg(all(target_os = "linux", feature = "window"))]
|
||||
|
||||
use BuilderAttribs;
|
||||
use ContextError;
|
||||
use CreationError;
|
||||
use GlContext;
|
||||
use GlProfile;
|
||||
@@ -139,11 +140,13 @@ impl Context {
|
||||
}
|
||||
|
||||
impl GlContext for Context {
|
||||
unsafe fn make_current(&self) {
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
// TODO: glutin needs some internal changes for proper error recovery
|
||||
let res = self.glx.MakeCurrent(self.display as *mut _, self.window, self.context);
|
||||
if res == 0 {
|
||||
panic!("glx::MakeCurrent failed");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_current(&self) -> bool {
|
||||
@@ -158,10 +161,10 @@ impl GlContext for Context {
|
||||
}
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
unsafe {
|
||||
self.glx.SwapBuffers(self.display as *mut _, self.window)
|
||||
}
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
// TODO: glutin needs some internal changes for proper error recovery
|
||||
unsafe { self.glx.SwapBuffers(self.display as *mut _, self.window); }
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_api(&self) -> ::Api {
|
||||
|
||||
@@ -4,6 +4,7 @@ extern crate osmesa_sys;
|
||||
|
||||
use Api;
|
||||
use BuilderAttribs;
|
||||
use ContextError;
|
||||
use CreationError;
|
||||
use GlContext;
|
||||
use PixelFormat;
|
||||
@@ -67,14 +68,18 @@ impl OsMesaContext {
|
||||
}
|
||||
|
||||
impl GlContext for OsMesaContext {
|
||||
unsafe fn make_current(&self) {
|
||||
let ret = osmesa_sys::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);
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
let ret = osmesa_sys::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);
|
||||
|
||||
// an error can only happen in case of invalid parameter, which would indicate a bug
|
||||
// in glutin
|
||||
if ret == 0 {
|
||||
panic!("OSMesaMakeCurrent failed")
|
||||
panic!("OSMesaMakeCurrent failed");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_current(&self) -> bool {
|
||||
@@ -88,7 +93,8 @@ impl GlContext for OsMesaContext {
|
||||
}
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_api(&self) -> Api {
|
||||
|
||||
@@ -9,6 +9,7 @@ use api::dlopen;
|
||||
use api::egl::Context as EglContext;
|
||||
|
||||
use BuilderAttribs;
|
||||
use ContextError;
|
||||
use CreationError;
|
||||
use Event;
|
||||
use PixelFormat;
|
||||
@@ -282,8 +283,7 @@ impl Window {
|
||||
}
|
||||
|
||||
impl GlContext for Window {
|
||||
|
||||
unsafe fn make_current(&self) {
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
self.context.make_current()
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ impl GlContext for Window {
|
||||
self.context.get_proc_address(addr)
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
self.context.swap_buffers()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#![cfg(any(target_os = "windows"))]
|
||||
|
||||
use BuilderAttribs;
|
||||
use ContextError;
|
||||
use CreationError;
|
||||
use GlContext;
|
||||
use GlRequest;
|
||||
@@ -156,9 +157,12 @@ impl Context {
|
||||
}
|
||||
|
||||
impl GlContext for Context {
|
||||
unsafe fn make_current(&self) {
|
||||
// TODO: check return value
|
||||
gl::wgl::MakeCurrent(self.hdc as *const _, self.context.0 as *const _);
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
if gl::wgl::MakeCurrent(self.hdc as *const _, self.context.0 as *const _) != 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ContextError::IoError(io::Error::last_os_error()))
|
||||
}
|
||||
}
|
||||
|
||||
fn is_current(&self) -> bool {
|
||||
@@ -176,9 +180,11 @@ impl GlContext for Context {
|
||||
}
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
unsafe {
|
||||
gdi32::SwapBuffers(self.hdc);
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
if unsafe { gdi32::SwapBuffers(self.hdc) } != 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ContextError::IoError(io::Error::last_os_error()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use std::sync::{
|
||||
};
|
||||
use std::sync::mpsc::Receiver;
|
||||
use libc;
|
||||
use ContextError;
|
||||
use {CreationError, Event, MouseCursor};
|
||||
use CursorState;
|
||||
use GlContext;
|
||||
@@ -315,7 +316,7 @@ impl Window {
|
||||
}
|
||||
|
||||
impl GlContext for Window {
|
||||
unsafe fn make_current(&self) {
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
match self.context {
|
||||
Context::Wgl(ref c) => c.make_current(),
|
||||
Context::Egl(ref c) => c.make_current(),
|
||||
@@ -336,7 +337,7 @@ impl GlContext for Window {
|
||||
}
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
match self.context {
|
||||
Context::Wgl(ref c) => c.swap_buffers(),
|
||||
Context::Egl(ref c) => c.swap_buffers(),
|
||||
|
||||
@@ -9,6 +9,7 @@ use std::collections::VecDeque;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use Api;
|
||||
use ContextError;
|
||||
use CursorState;
|
||||
use GlContext;
|
||||
use GlRequest;
|
||||
@@ -800,11 +801,11 @@ impl Window {
|
||||
}
|
||||
|
||||
impl GlContext for Window {
|
||||
unsafe fn make_current(&self) {
|
||||
unsafe fn make_current(&self) -> Result<(), ContextError> {
|
||||
match self.x.context {
|
||||
Context::Glx(ref ctxt) => ctxt.make_current(),
|
||||
Context::Egl(ref ctxt) => ctxt.make_current(),
|
||||
Context::None => {}
|
||||
Context::None => Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -824,11 +825,11 @@ impl GlContext for Window {
|
||||
}
|
||||
}
|
||||
|
||||
fn swap_buffers(&self) {
|
||||
fn swap_buffers(&self) -> Result<(), ContextError> {
|
||||
match self.x.context {
|
||||
Context::Glx(ref ctxt) => ctxt.swap_buffers(),
|
||||
Context::Egl(ref ctxt) => ctxt.swap_buffers(),
|
||||
Context::None => {}
|
||||
Context::None => Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user