Whenever I pass an argument to emscripten_set_main_loop_arg, it looks like 
it becomes a dangling pointer...
I'm very new to rust, so I might be missing something very obvious.

How can I go somewhere, if my application states/variables can't stay valid 
between to steps of my main loop?

Here is my source code (main.rs) :

// tried with cargo rustc --release --target wasm32-unknown-emscripten
// and with cargo rustc asmjs-unknown-emscripten -- -C link-args="-g4"

// bindings for emscripten_set_main_loop_arg in Rust:

#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

pub type em_arg_callback_func = Option<unsafe extern "C" fn(arg1: *mut 
::std::os::raw::c_void)>;

extern "C" {
    pub fn emscripten_set_main_loop_arg(
        func: em_arg_callback_func,
        arg: *mut ::std::os::raw::c_void,
        fps: ::std::os::raw::c_int,
        simulate_infinite_loop: ::std::os::raw::c_int,
    );
}

// my program

struct ApplicationData {
    some_value: u32,
}

extern "C" fn loop_wrapper(ctx: *mut std::os::raw::c_void) {
    unsafe {
        let a = &mut *(ctx as *mut ApplicationData );
        println!("{}", a.some_value); // doesn't print '1982' :(
    }
}

fn main() {
    unsafe {
        let mut a = ApplicationData { some_value:1982 };
        let ptr = &mut a as *mut _ as *mut std::os::raw::c_void;
        emscripten_set_main_loop_arg(Some(loop_wrapper), ptr, 0, 1);
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to