Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::rt::start_on_main_thread no longer exists? #62

Closed
bonsairobo opened this issue Dec 27, 2013 · 5 comments
Closed

std::rt::start_on_main_thread no longer exists? #62

bonsairobo opened this issue Dec 27, 2013 · 5 comments

Comments

@bonsairobo
Copy link

I get the compile error
unresolved name std::rt::start_on_main_thread
when trying to build any of the examples. I also looked in rust's repo under libstd/rt and couldn't find any instances of the function "start_on_main_thread".

@ghost
Copy link

ghost commented Dec 27, 2013

It's a side effect of this change. rust-lang/rust#10965. Alex posted a potential work around.

extern mod native;
extern mod green;

use std::task::TaskOpts;

#[start]
fn start(argc: int, argv: **u8) -> int {
    do native::start(argc, argv) {
        let mut pool = green::SchedPool::new(green::PoolConfig::new());
        let (p, c) = Chan::new();
        do pool.spawn(TaskOpts::new()) {
            println!("green pool");
            c.send(());
        }
        p.recv();
        pool.shutdown();
    }
}

@bonsairobo
Copy link
Author

Is native ready to be used?

error: Package examples/window depends on native, but I don't know how to find it 

@ghost
Copy link

ghost commented Dec 27, 2013

Compiling with rustc instead of rustpkg seems to work as a temporary work around. It looks like there is a bug in rustpkg.

extern mod glfw;
extern mod native;

use std::libc;

#[link(name="glfw")]
extern {}

#[start]
fn start(argc: int, argv: **u8) -> int {
    do native::start(argc, argv) {
        main();
    }
}

This seems to give me a working window.

@bonsairobo
Copy link
Author

I get a segfault. I've built glfw3 from master, glfw-rs from master (had to rename libglfw3.so to libglfw.so for linking to work), then compiled this:

// build command: rustc main.rs -o window -L../../../lib/i686-unknown-linux-gnu

extern mod glfw;
extern mod native;

use std::libc;

#[link(name="glfw")]
extern {}

#[start]
fn start(argc: int, argv: **u8) -> int {
    do native::start(argc, argv) {
        main();
    }
}

fn main() {
    glfw::set_error_callback(~ErrorContext);

    do glfw::start {
        let window = glfw::Window::create(300, 300, "Hello this is window", glfw::Windowed)
            .expect("Failed to create GLFW window.");

        window.set_key_callback(~KeyContext);
        window.make_context_current();

        while !window.should_close() {
            glfw::poll_events();
        }
    }
}

struct ErrorContext;
impl glfw::ErrorCallback for ErrorContext {
    fn call(&self, _: glfw::Error, description: ~str) {
        println!("GLFW Error: {:s}", description);
    }
}

struct KeyContext;
impl glfw::KeyCallback for KeyContext {
    fn call(&self, window: &glfw::Window, key: glfw::Key, _: libc::c_int, action: glfw::Action, _: glfw::Modifiers) {
        if action == glfw::Press && key == glfw::KeyEscape {
            window.set_should_close(true);
        }
    }
}

@brendanzab
Copy link
Member

Fixed in #65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants