Skip to content

Commit

Permalink
Retain calayer after creation (#546)
Browse files Browse the repository at this point in the history
* Retain calayer after creation

* Fix fmt

* fix create_calayer test
  • Loading branch information
xiaopengli89 authored Aug 9, 2024
1 parent 652bab0 commit b10f1ef
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cocoa/src/quartzcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ impl CALayer {

#[inline]
pub fn new() -> CALayer {
unsafe { CALayer(msg_send![class!(CALayer), layer]) }
unsafe {
let id: id = msg_send![class!(CALayer), layer];
let _: id = msg_send![id, retain];
CALayer(id)
}
}

#[inline]
Expand Down Expand Up @@ -1680,3 +1684,15 @@ pub type CVSMPTETimeFlags = u32;

pub const kCVSMPTETimeValid: CVSMPTETimeFlags = 1 << 0;
pub const kCVSMPTETimeRunning: CVSMPTETimeFlags = 1 << 1;

#[cfg(test)]
mod test {
use super::CALayer;

#[test]
fn create_calayer() {
objc::rc::autoreleasepool(|| {
let _ = CALayer::new();
});
}
}

0 comments on commit b10f1ef

Please sign in to comment.