From 4df077f9b26526552aff934203c577d0367d15ac Mon Sep 17 00:00:00 2001 From: Jae-Sung Lee Date: Fri, 3 Oct 2025 08:50:40 +0900 Subject: [PATCH] fix panic when adding menuroles on linux (#4558) * fix panic when adding menuroles on linux * update changelog --------- Co-authored-by: Lea Anthony --- v2/internal/frontend/desktop/linux/menu.go | 13 +++++++++---- website/src/pages/changelog.mdx | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/v2/internal/frontend/desktop/linux/menu.go b/v2/internal/frontend/desktop/linux/menu.go index 557a24b37..a61d190bd 100644 --- a/v2/internal/frontend/desktop/linux/menu.go +++ b/v2/internal/frontend/desktop/linux/menu.go @@ -34,8 +34,11 @@ void addAccelerator(GtkWidget* menuItem, GtkAccelGroup* group, guint key, GdkMod } */ import "C" -import "github.com/wailsapp/wails/v2/pkg/menu" -import "unsafe" +import ( + "unsafe" + + "github.com/wailsapp/wails/v2/pkg/menu" +) var menuIdCounter int var menuItemToId map[*menu.MenuItem]int @@ -81,8 +84,10 @@ func (w *Window) SetApplicationMenu(inmenu *menu.Menu) { func processMenu(window *Window, menu *menu.Menu) { for _, menuItem := range menu.Items { - submenu := processSubmenu(menuItem, window.accels) - C.gtk_menu_shell_append(C.toGtkMenuShell(unsafe.Pointer(window.menubar)), submenu) + if menuItem.SubMenu != nil { + submenu := processSubmenu(menuItem, window.accels) + C.gtk_menu_shell_append(C.toGtkMenuShell(unsafe.Pointer(window.menubar)), submenu) + } } } diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 30a50c16b..5a20501f9 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added url validation for BrowserOpenURL by @APshenkin in [PR](https://github.com/wailsapp/wails/pull/4484) - Fixed C compilation error in onWayland on Linux due to declaration after label [#4446](https://github.com/wailsapp/wails/pull/4446) by [@jaesung9507](https://github.com/jaesung9507) - Use computed style when adding 'wails-drop-target-active' [PR](https://github.com/wailsapp/wails/pull/4420) by [@riannucci](https://github.com/riannucci) +- Fixed panic when adding menuroles on Linux [#4558](https://github.com/wailsapp/wails/pull/4558) by [@jaesung9507](https://github.com/jaesung9507) ## v2.10.2 - 2025-07-06