rust-windowing / winit

Window handling library in pure Rust
https://docs.rs/winit/
Apache License 2.0
4.84k stars 902 forks source link

Winit raises SIGTRAP error when used in conjunction with enigo #2829

Closed waffleattack closed 1 year ago

waffleattack commented 1 year ago

[Optional] Relevant system information

M1 Macbook Air, Running Macos Ventura 13.3.1

What you did

While attempting to make a macro recorder app that uses engo to simulate key presses and bevy as a display, encountered SIGTRAP when trying to simulate keypress.

To Reproduce:

use std::thread;
use std::time::Duration;

use enigo::{Enigo, Key, KeyboardControllable};
use winit::{
    event::{Event, WindowEvent},
    event_loop::{ControlFlow, EventLoop},
    window::WindowBuilder,
};

fn main() {
    thread::spawn(|| {
        thread::sleep(Duration::from_millis(5000));
        let mut engio = Enigo::new();
        engio.key_click(Key::Layout('u'));
    });
    let event_loop = EventLoop::new();
    let window = WindowBuilder::new().build(&event_loop).unwrap();

    event_loop.run(move |event, _, control_flow| {
        *control_flow = ControlFlow::Wait;

        match event {
            Event::WindowEvent {
                event: WindowEvent::CloseRequested,
                window_id,
            } if window_id == window.id() => *control_flow = ControlFlow::Exit,
            _ => (),
        }
    });
}

What went wrong

App crashed and printed this error to console

Process finished with exit code 133 (interrupted by signal 5: SIGTRAP)
kchibisov commented 1 year ago

Are you sure that the trap is inside the winit? Also, be aware that given that you do some stuff on macOS off the main thread, you might have issues with that, if engio uses macOS API it must call them from the main thread as well, so it might be it trapping.

kchibisov commented 1 year ago

I'd close this as not a winit issue.