Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ winapi = "0.2"
gdi32-sys = "0.2"
user32-sys = "0.2"
kernel32-sys = "0.2"
lazy_static = "0.2"

[target.'cfg(any(target_os="macos", target_os="windows"))'.dependencies]
lazy_static = "0.2"
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern crate kernel32;
extern crate gdi32;
#[cfg(target_os = "windows")]
extern crate user32;
#[cfg(target_os = "windows")]
#[cfg(any(target_os="macos", target_os="windows"))]
#[macro_use]
extern crate lazy_static;

Expand Down
11 changes: 11 additions & 0 deletions src/platform/with_cgl/native_gl_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFuncti
use core_foundation::base::TCFType;
use core_foundation::string::CFString;
use std::str::FromStr;
use std::sync::Mutex;

use platform::NativeGLContextMethods;

lazy_static! {
static ref CHOOSE_PIXEL_FORMAT_MUTEX: Mutex<()> = Mutex::new(());
}

pub struct NativeGLContextHandle(CGLContextObj);

unsafe impl Send for NativeGLContextHandle {}
Expand Down Expand Up @@ -94,6 +99,12 @@ impl NativeGLContextMethods for NativeGLContext {
}

fn create_shared(with: Option<&Self::Handle>) -> Result<NativeGLContext, &'static str> {
// CGLChoosePixelFormat fails if multiple threads try to open a display connection
// simultaneously. The following error is returned by CGLChoosePixelFormat:
// kCGLBadConnection - Invalid connection to Core Graphics.
// We use a static mutex guard to fix this issue
let _guard = CHOOSE_PIXEL_FORMAT_MUTEX.lock().unwrap();

let mut attributes = [
0
];
Expand Down