BillyDM / egui-baseview

A baseview backend for the egui Rust GUI library
MIT License
22 stars 17 forks source link

The window close does not stop / drop the egui loop #6

Open alamminsalo opened 2 years ago

alamminsalo commented 2 years ago

When reopening vst plugin window, the earlier draw loop continues to run, leading to multiple simultaneous ui-processes running.

Steps to reproduce: add times_opened usize to editor and pass incremented copy of it to window state. Then close and reopen window couple of times:

    fn close(&mut self) {
        self.is_open = false;
        if let Some(mut window_handle) = self.window_handle.take() {
            (window_handle.0).close();
        }
    }

    fn open(&mut self, parent: *mut ::std::ffi::c_void) -> bool {
        match self.is_open() {
            true => false,
            false => {
                // info!("Open editor");
                self.is_open = true;
                self.times_opened += 1;

                let settings = Settings {
                    ...
                };

                let window_handle = EguiWindow::open_parented(
                    &VstParent(parent),
                    settings,
                    (
                        self.times_opened,
                    ),
                    |_egui_ctx, _queue, _state| {},
                    |egui_ctx: &CtxRef, _, (times_opened)| {
                        info!("{}: draw", times_opened);
                        ui::draw_ui(egui_ctx); // ui draw func
                    },
                );

                self.window_handle = Some(WindowParent(window_handle));
                true
            }
        }

If opened 2 times, this prints continuously

1: draw
2: draw
1: draw
2: draw
...
BillyDM commented 1 year ago

Oh sorry, I'm really late to this one.

I've just made some changes that updates to using egui 0.19, so can you test if this is still an issue?

valsteen commented 7 months ago

Hi, I experienced the same issue, this is on MacOS. I experimented by changing the dependency to this commit of baseview https://github.com/RustAudio/baseview/commit/2c1b1a7b0fef1a29a5150a6a8f6fef6a0cbab8c4 , which conveniently addresses the following issue: Fix window cleanup logic on macOS. I can confirm update stopped being called after I closed the window.