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

Program crash after closing tray-icon menu without clicking any options #115

Open
juance20 opened this issue Feb 11, 2024 · 2 comments
Open

Comments

@juance20
Copy link

As the title says, when you right-click on a tray-icon the menu pops up as normal, but if you close the menu by clicking anywhere else the program simply crashes, giving the "STATUS_ACCESS_VIOLATION" error.
This was made on windows 10 pro 19045.3930.
This is my code stating the tray icon, menu and menu item:

let my_menu: Menu = Menu::new();

let _ = my_menu.append(&PredefinedMenuItem::quit(Some("Terminar")));

let _tray_icon: TrayIcon = TrayIconBuilder::new()
    .with_tooltip("Anti-AFK")
    .with_icon(icono)
    .with_menu(Box::new(my_menu))
    .build()
    .unwrap();
@amrbashir
Copy link
Member

I can't reproduce at all, could you share your full example?

@jonatino
Copy link

jonatino commented Oct 8, 2024

@amrbashir I have this issue as well. For some reason, it only happens when I use a keyboard hook crate on windows.

Cargo.toml

[package]
name = "untitled"
version = "0.1.0"
edition = "2021"

[dependencies]
tray-icon = "0.19.0"
rdev = { version =  "0.5.3", features = ["unstable_grab"] }

main.rs

use rdev::{grab, Event};
use tray_icon::menu::Menu;
use tray_icon::{Icon, TrayIconBuilder};

fn keyboard_callback(event: Event) -> Option<Event> {
    Some(event)
}

fn main() {
    let tray_menu = Menu::new();
    let tray_icon = TrayIconBuilder::new()
        .with_menu(Box::new(tray_menu))
        .with_tooltip("system-tray - tray icon library!")
        .with_icon(Icon::from_rgba(vec![255; 16 * 16 * 4], 16, 16).unwrap())
        .build()
        .unwrap();

    tray_icon.set_visible(true).expect("TODO: panic message");

    // Load keyboard hook. Idk why I but I only get the STATUS_ACCESS_VIOLATION when using the code like this
    if let Err(error) = grab(keyboard_callback) {
        println!("Error: {:?}", error)
    }
}

This will cause a STATUS_ACCESS_VIOLATION every time u mouse over, right click, or move the system tray icon on Windows 11. Probably similar to what OP had above but with a different crate likely.

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

3 participants