Skip to content

#266 (Windows Thread-based DPI awareness) causes Ableton to crash #274

@AlexCharlton

Description

@AlexCharlton

#266 has resulted in the opening of a baseview window in Ableton to crash. The same plugin built with baseview prior to #266 is able to open with no issues.

The crash is caused by a panic: thread 'unnamed' panicked at 'RefCell already borrowed': C:\programming\external\baseview\src\win\window.rs:526, which corresponds to handle_event calling self.handler.borrow_mut.

It seems that Ableton triggers a number of events while opening the window:

13:54:44 [INFO] baseview::win::window: handle_event call site: WM_MOUSEMOVE CursorEntered
13:54:44 [INFO] baseview::win::window: handle_event call site: WM_MOUSEMOVE CursorMoved
13:54:44 [INFO] baseview::win::window: handle_event call site: WM_SETFOCUS Focused
13:54:44 [INFO] baseview::win::window: handle_event call site: WM_*BUTTON* ButtonReleased { button: Left, modifiers: NUM_LOCK }
13:54:44 [INFO] baseview::win::window: handle_event call site: WM_MOUSEMOVE CursorMoved
13:54:44 [INFO] baseview::win::window: handle_event call site: WM_SIZE Resized
13:54:44 [ERROR] nice_plug::wrapper::util: thread 'unnamed' panicked at 'RefCell already borrowed': C:\programming\external\baseview\src\win\window.rs:526

The panic can be avoided by calling try_borrow_mut:

pub(crate) fn handle_event(&self, event: Event) -> EventStatus {
        let Ok(mut handler) = self.handler.try_borrow_mut() else {
            return EventStatus::Ignored;
        };

        let Some(handler) = handler.as_mut() else {
            return EventStatus::Ignored;
        };

        let mut window = crate::window::Window::new(Window { state: self });
        handler.on_event(&mut window, event)
    }

But this of course causes the event to be ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions