ryanmcgrath/cacao

Window closes on blocking operations

Isaac-Leonard opened this issue · 2 comments

Not sure if its an issue with Cacao or macOS itself but it seems as though my main window in cacao apps closes if I perform a blocking operation on the main thread for too long.
I don't really have any good examples atm but running the following code in the on_ui_message method should replicate it:


                let len = 1024usize.pow(3);
                let mut vec = Vec::with_capacity(len);
                for i in 0..len {
                    vec.push(std::time::SystemTime::now());
                }
                for i in &vec {
                    if i.duration_since(std::time::SystemTime::UNIX_EPOCH).unwrap()
                        > Duration::from_secs(365 * 24 * 60 * 60 * 100)
                    {
                        eprintln!("Its 2070");
                    }
                }
                eprintln!("Len: {:?}", vec.len());
            

Simply calling sleep(Duration::from_secs(xxx)) doesn't seem to do it so maybe there has to be an element of work being done or large memory allocation, I'm not quite sure.
This is happening for me in an unoptimised image processing algorithm I'm running and I'd like to verify its working before preceding but currently can't because it just crashes the window.
Do you know what might be going on?

Uhh to be clear: is this closing the window or crashing the application? If the latter - is there a log or backtrace?

The usual "don't block the main thread" rule applies here but if you have more details it's certainly worth a look.

Yeah, it just closes the window, the application stays open.
For the above code I get a warning about blocking the main thread or something but not for my image code.
Guess I'll try move it to run in a seperate thread and see if that helps