nwg-piotr / nwg-dock-hyprland

GTK3-based dock for Hyprland
MIT License
190 stars 14 forks source link

Crashes on 0.1.6 if there's no icon for app in current theme #25

Closed theRealCarneiro closed 5 months ago

theRealCarneiro commented 1 year ago

Describe the bug The dock crashes when there's an open app that does not have an icon for it in the current icon theme. If the app that's causing crashes is closed, the dock will work as expected, as soon as it open the dock crashes. And it doesn't even start when the app is already open.

INFO[0000] Using auto-detected launcher command: 'nwg-drawer'
INFO[0000] Using style: /home/gabriel/.config/nwg-dock-hyprland/style.css
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x559f080eb997]

goroutine 1 [running]:
github.com/gotk3/gotk3/gtk.(*Image).toWidget(0x559f080c8a40?)
    <autogenerated>:1 +0x17
main.taskButton.(*Button).SetImage.func4(0xc00021c5f0?, {0x559f0825fa20, 0x0})
    github.com/gotk3/gotk3@v0.6.2/gtk/gtk.go:1853 +0x3a
github.com/gotk3/gotk3/gtk.(*Button).SetImage(...)
    github.com/gotk3/gotk3@v0.6.2/gtk/gtk.go:1853
main.taskButton({{0xc00021b160, 0xe}, 0x1, 0x0, {0xc00021b170, 0x2, 0x2}, {0xc00021b1a0, 0x2, 0x2}, ...}, ...)
    ./tools.go:117 +0x18b
main.buildMainBox(0x559f0836ce60?)
    ./main.go:163 +0xa38
main.main()
    ./main.go:557 +0x121e

To Reproduce Steps to reproduce the behavior:

  1. Open the dock
  2. Crash

Expected behavior Not crash

Desktop (please complete the following information):

Additional context Have seen this happen with Whatsapp Nativefier, Steam Games, or anything that does not have a specific icon for it in the current theme

nwg-piotr commented 1 year ago

You didn't specify your icon theme, so I couldn't reproduce the issue, and had to try and fix it blindly. Hope it's going to help.

theRealCarneiro commented 1 year ago

The icon theme is Papirus-Dark, from the papirus-icon-theme from the oficial arch repos. Whatsapp Nativefier pkg from the aur is one that crashes the dock. I just updated it and now i just get a new error (even with everything closed):

 ~  nwg-dock-hyprland
INFO[0000] Using auto-detected launcher command: 'nwg-drawer'
INFO[0000] Using style: /home/gabriel/.config/nwg-dock-hyprland/style.css
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x5609b206c723]

goroutine 1 [running]:
main.buildMainBox(0x5609b22e9e60?)
    ./main.go:217 +0xbe3
main.main()
    ./main.go:559 +0x129e
nwg-piotr commented 1 year ago

It doesn't happen to me. Tried on 3 various machines, the dock didn't crash on any of them.

Where do you install whatsapp-nativefier from? What's on AUR, does not work for me.

dusanx commented 5 months ago

I can confirm that this happens for 70% of icon themes I try

> nwg-dock-hyprland -x

INFO[0000] Using auto-detected launcher command: 'nwg-drawer'
INFO[0000] Using style: /home/dusanx/.config/nwg-dock-hyprland/style.css
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x557d46f03437]

goroutine 1 [running]:
github.com/gotk3/gotk3/gtk.(*Image).toWidget(0x557d46f1216e?)
    <autogenerated>:1 +0x17
main.pinnedButton.(*Button).SetImage.func4(0xc000020340?, {0x557d47082740, 0x0})
    github.com/gotk3/gotk3@v0.6.3/gtk/gtk.go:1853 +0x3a
github.com/gotk3/gotk3/gtk.(*Button).SetImage(...)
    github.com/gotk3/gotk3@v0.6.3/gtk/gtk.go:1853
main.pinnedButton({0xc000020340, 0x6})
    ./tools.go:45 +0x105
main.buildMainBox(0xc00005c128)
    ./main.go:128 +0x7e7
main.main()
    ./main.go:567 +0x145e

For example with extra/pop-icon-theme but with many others too.

My dock contains:

  1. Thunar, showing Icon=thunar
  2. Emacs, showing Icon=emacs
  3. Kitty terminal, showing Icon=terminal
  4. Firefox, showing Icon=browser

I can't claim if icon set contains the icon (can dig if needed) that causes crash but I can test anything you want.

Edit: quick check shows that 'pop' theme doesn't have 'thunar' nor 'emacs' icons. This should be easy to simulate.

dusanx commented 5 months ago

@nwg-piotr please patch next version with this one line change:

diff --git a/tools.go b/tools.go
index f0c0540..7e6af62 100644
--- a/tools.go
+++ b/tools.go
@@ -32,7 +32,7 @@ func pinnedButton(ID string) *gtk.Box {
        box.PackStart(button, false, false, 0)

        image, err := createImage(ID, imgSizeScaled)
-       if err != nil {
+       if ((err != nil) || (image == nil)) {
                pixbuf, err := gdk.PixbufNewFromFileAtSize(filepath.Join(dataHome, "nwg-dock-hyprland/images/icon-missing.svg"),
                        imgSizeScaled, imgSizeScaled)
                if err == nil {

Reason for crash was that tools.go in line 34 image, err := createImage(ID, imgSizeScaled) was returning image = nil and err = nil when icon is missing, so next if line didn't fire. With new check in line 35 crash doesn't happen any more. It was too tiny change to create proper merge request but this solves the issue.

nwg-piotr commented 5 months ago

OK, got it. Thanks.