diff --git a/.changes/checked-borrow-panic.md b/.changes/checked-borrow-panic.md new file mode 100644 index 0000000..270548d --- /dev/null +++ b/.changes/checked-borrow-panic.md @@ -0,0 +1,5 @@ +--- +"muda": "patch" +--- + +Fix panic when updating a `CheckMenuItem` right after it was clicked. diff --git a/examples/tao.rs b/examples/tao.rs index b7b45bd..60ca3fc 100644 --- a/examples/tao.rs +++ b/examples/tao.rs @@ -106,6 +106,7 @@ fn main() { &window_m, &PredefinedMenuItem::separator(), &check_custom_i_1, + &check_custom_i_2, ]); window_m.append_items(&[ diff --git a/examples/winit.rs b/examples/winit.rs index 793d57d..e6d5896 100644 --- a/examples/winit.rs +++ b/examples/winit.rs @@ -101,6 +101,7 @@ fn main() { &window_m, &PredefinedMenuItem::separator(), &check_custom_i_1, + &check_custom_i_2, ]); window_m.append_items(&[ diff --git a/src/icon_menu_item.rs b/src/icon_menu_item.rs index 4404089..cd426c7 100644 --- a/src/icon_menu_item.rs +++ b/src/icon_menu_item.rs @@ -4,9 +4,8 @@ use crate::{accelerator::Accelerator, icon::Icon, MenuItemExt, MenuItemType}; -/// A check menu item inside a [`Menu`] or [`Submenu`] -/// and usually contains a text and a check mark or a similar toggle -/// that corresponds to a checked and unchecked states. +/// An icon menu item inside a [`Menu`] or [`Submenu`] +/// and usually contains an icon and a text. /// /// [`Menu`]: crate::Menu /// [`Submenu`]: crate::Submenu diff --git a/src/platform_impl/gtk/mod.rs b/src/platform_impl/gtk/mod.rs index f5d0f3b..1d73d6c 100644 --- a/src/platform_impl/gtk/mod.rs +++ b/src/platform_impl/gtk/mod.rs @@ -1041,10 +1041,9 @@ impl CheckMenuItem { let id = self_.id; let self_c = self.0.clone(); + let is_syncing_checked_state = self_.is_syncing_checked_state.clone(); item.connect_toggled(move |i| { - let should_dispatch = self_c - .borrow() - .is_syncing_checked_state + let should_dispatch = is_syncing_checked_state .compare_exchange(false, true, Ordering::Release, Ordering::Relaxed) .is_ok();