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

Window closes on blocking operations #110

Open
Isaac-Leonard opened this issue Oct 9, 2023 · 2 comments
Open

Window closes on blocking operations #110

Isaac-Leonard opened this issue Oct 9, 2023 · 2 comments

Comments

@Isaac-Leonard
Copy link

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?

@ryanmcgrath
Copy link
Owner

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.

@Isaac-Leonard
Copy link
Author

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

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