servo / cocoa-rs

DEPRECATED - Cocoa/Objective-C bindings for the Rust programming language
https://github.com/servo/core-foundation-rs/
Other
286 stars 72 forks source link

Assertion error with basic usage of NSStatusBar #149

Open frewsxcv opened 7 years ago

frewsxcv commented 7 years ago

https://developer.apple.com/reference/appkit/nsstatusbar/1530619-systemstatusbar?language=objc

extern crate cocoa;

use cocoa::appkit::NSStatusBar;
use cocoa::base::nil;

fn main() {
    unsafe {
        let _ = NSStatusBar::systemStatusBar(nil);
    }
}
> cargo run
   Compiling mac-menu-bar v0.1.0 (file:///Users/corey/dev/rust-mac-menu-bar)
    Finished debug [unoptimized + debuginfo] target(s) in 0.30 secs
     Running `target/debug/mac-menu-bar`
Assertion failed: (CGAtomicGet(&is_initialized)), function CGSConnectionByID, file Services/Connection/CGSConnection.c, line 127.
viraptor commented 7 years ago

For more info, confirming on rust 1.15.1 and libs:

   Compiling core-foundation-sys v0.3.1
   Compiling objc v0.2.2
   Compiling core-foundation v0.3.0
   Compiling core-graphics v0.7.0
   Compiling cocoa v0.8.0
savruk commented 7 years ago

This on the other hand compiles(rustc 1.17.0, cocoa = "0.8.1"):

extern crate cocoa;

use cocoa::appkit::{NSStatusBar, NSApp};
use cocoa::base::nil;

fn main() {
    unsafe {
        let app = NSApp();  // initialising the app first does the trick for me
        let _ = NSStatusBar::systemStatusBar(nil);
    }
}
frewsxcv commented 7 years ago

Yep, initializing the app first seems to be required. Ideally, there'd be a better error for this scenario, but I'm not sure there's much we can do. If there's not much we can do here, this issue can be closed I suppose.