mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-12 05:31:31 +11:00
add and use IdRef::non_nil() instead of doing deref'd comparisons against nil
This commit is contained in:
parent
1b2fd6e6d0
commit
cf630ec041
|
@ -456,10 +456,7 @@ impl Window {
|
||||||
NSBackingStoreBuffered,
|
NSBackingStoreBuffered,
|
||||||
NO,
|
NO,
|
||||||
));
|
));
|
||||||
|
window.non_nil().map(|window| {
|
||||||
if *window == nil {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
let title = IdRef::new(NSString::alloc(nil).init_str(title));
|
let title = IdRef::new(NSString::alloc(nil).init_str(title));
|
||||||
window.setTitle_(*title);
|
window.setTitle_(*title);
|
||||||
window.setAcceptsMouseMovedEvents_(YES);
|
window.setAcceptsMouseMovedEvents_(YES);
|
||||||
|
@ -469,21 +466,19 @@ impl Window {
|
||||||
else {
|
else {
|
||||||
window.center();
|
window.center();
|
||||||
}
|
}
|
||||||
Some(window)
|
window
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_view(window: id) -> Option<IdRef> {
|
fn create_view(window: id) -> Option<IdRef> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let view = IdRef::new(NSView::alloc(nil).init());
|
let view = IdRef::new(NSView::alloc(nil).init());
|
||||||
if *view == nil {
|
view.non_nil().map(|view| {
|
||||||
None
|
|
||||||
} else {
|
|
||||||
view.setWantsBestResolutionOpenGLSurface_(YES);
|
view.setWantsBestResolutionOpenGLSurface_(YES);
|
||||||
window.setContentView_(*view);
|
window.setContentView_(*view);
|
||||||
Some(view)
|
view
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,21 +508,17 @@ impl Window {
|
||||||
];
|
];
|
||||||
|
|
||||||
let pixelformat = IdRef::new(NSOpenGLPixelFormat::alloc(nil).initWithAttributes_(&attributes));
|
let pixelformat = IdRef::new(NSOpenGLPixelFormat::alloc(nil).initWithAttributes_(&attributes));
|
||||||
if *pixelformat == nil {
|
pixelformat.non_nil().map(|pixelformat| {
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let context = IdRef::new(NSOpenGLContext::alloc(nil).initWithFormat_shareContext_(*pixelformat, nil));
|
let context = IdRef::new(NSOpenGLContext::alloc(nil).initWithFormat_shareContext_(*pixelformat, nil));
|
||||||
if *context == nil {
|
context.non_nil().map(|context| {
|
||||||
None
|
|
||||||
} else {
|
|
||||||
context.setView_(view);
|
context.setView_(view);
|
||||||
if vsync {
|
if vsync {
|
||||||
let value = 1;
|
let value = 1;
|
||||||
context.setValues_forParameter_(&value, NSOpenGLContextParameter::NSOpenGLCPSwapInterval);
|
context.setValues_forParameter_(&value, NSOpenGLContextParameter::NSOpenGLCPSwapInterval);
|
||||||
}
|
}
|
||||||
Some(context)
|
context
|
||||||
}
|
})
|
||||||
|
}).unwrap_or(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -715,9 +706,15 @@ impl IdRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retain(i: id) -> IdRef {
|
fn retain(i: id) -> IdRef {
|
||||||
|
if i != nil {
|
||||||
unsafe { msg_send::<()>()(i, selector("retain")) };
|
unsafe { msg_send::<()>()(i, selector("retain")) };
|
||||||
|
}
|
||||||
IdRef(i)
|
IdRef(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn non_nil(self) -> Option<IdRef> {
|
||||||
|
if self.0 == nil { None } else { Some(self) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for IdRef {
|
impl Drop for IdRef {
|
||||||
|
|
Loading…
Reference in a new issue