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

Trying to hide subsequently created popups in a goroutine results in Fyne runtime panic #5564

Closed
2 tasks done
ErikKalkoken opened this issue Feb 27, 2025 · 8 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@ErikKalkoken
Copy link
Contributor

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

We have a popup that reports on ongoing action to the user and hides itself again, once the action is completed. For example we might be fetching a large dataset from the Internet and want to show the user a modal dialog with a progress bar while he has to wait for the fetching to complete.

When we create multiple popups of this type the Fyne runtime often panics when trying to hide the popup again.

Here is an example panic message, which was produces by running the below example code:

panic: runtime error: index out of range [2] with length 2

goroutine 89 [running]:
fyne.io/fyne/v2/internal/driver/common.(*overlayStack).remove(0xc00026c900, {0xda9fa0?, 0xc00026c980?})
        /home/erik/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/common/canvas.go:563 +0x8d
fyne.io/fyne/v2/internal/driver/common.(*overlayStack).Remove(0xc00026c900, {0xda9fa0, 0xc00026c980})
        /home/erik/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/common/canvas.go:552 +0x52
fyne.io/fyne/v2/widget.(*PopUp).Hide(0xc00026c980)
        /home/erik/go/pkg/mod/fyne.io/fyne/[email protected]/widget/popup.go:28 +0x42
main.main.func1.1()
        /home/erik/go/evebuddy-project/fyne-playground/main.go:21 +0x17
created by main.main.func1 in goroutine 85
        /home/erik/go/evebuddy-project/fyne-playground/main.go:20 +0x39
exit status 2

Please note that we have seen the same behavior with normal popups, modal popups and dialogs.

How to reproduce

See example code.

Screenshots

For illustration here is an example dialog that shows progress about an ongoing action to the user:

Image

Example code

package main

import (
	"log"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Fyne Playground")
	w.SetContent(widget.NewLabel("Hello, World!"))
	w.Resize(fyne.NewSize(400, 300))
	a.Lifecycle().SetOnStarted(func() {
		for range 10 {
			p := widget.NewPopUp(widget.NewLabel("Content"), w.Canvas())
			p.Show()
			go func() {
				p.Hide()
			}()
		}
		log.Println("Done")
	})
	w.ShowAndRun()
}

Fyne version

2.5.4

Go compiler version

1.23.4

Operating system and version

Ubuntu 22.04

Additional Information

This bug was first encountered with 2.5.4. Since the related code did not change we suspect this bug was introduced with that patch.

@ErikKalkoken ErikKalkoken added the unverified A bug that has been reported but not verified label Feb 27, 2025
@andydotxyz
Copy link
Member

We should fix this panic. But you should also be careful not to throw up multiple popups without checking - they are stacked, so if you show 1 then 2 then 3 and then hide 1 then the other two will no longer be shown to the user.

@andydotxyz
Copy link
Member

Thanks for the demo code, that PR seems to address it :)

@ErikKalkoken
Copy link
Contributor Author

We should fix this panic. But you should also be careful not to throw up multiple popups without checking - they are stacked, so if you show 1 then 2 then 3 and then hide 1 then the other two will no longer be shown to the user.

ty for fixing this. And thanks for the important clarification on how to they work. In my experience it works fine as long as you hide them in lifo order, but that can of course not be guaranteed when showing multiple popups in parallel that close themselves after varying durations. So I will have to rethink the implementation of them.

@andydotxyz
Copy link
Member

In my experience it works fine as long as you hide them in lifo order

Yes it should indeed work that way - but as you say sometimes things may not be so well ordered in app lifecycle.

@Jacalz
Copy link
Member

Jacalz commented Feb 27, 2025

Does using v2.6 and fyne.Do() inside the goroutine solve the problem? If that is the case then this is likely a racy condition and we might not need a fix for it as it is undefined behaviour.

@ErikKalkoken
Copy link
Contributor Author

No. I tested it with 2.6.0-alpha1 and your instructions and getting a similar panic:

panic: runtime error: index out of range [1] with length 1

goroutine 1 [running, locked to thread]:
fyne.io/fyne/v2/internal/driver/common.(*overlayStack).remove(0xc00033da40, {0xdb02e0?, 0xc0002a2620?})
        /home/erik/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/common/canvas.go:534 +0x7f
fyne.io/fyne/v2/internal/driver/common.(*overlayStack).Remove(0xcef3c8?, {0xdb02e0?, 0xc0002a2620?})
        /home/erik/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/common/canvas.go:523 +0x29
fyne.io/fyne/v2/widget.(*PopUp).Hide(0xc0002a2620)
        /home/erik/go/pkg/mod/fyne.io/fyne/[email protected]/widget/popup.go:28 +0x42
main.main.func1.1.1()
        /home/erik/go/fyne26-dev/main.go:22 +0x17
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).runGL(0x47a472?)
        /home/erik/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/loop.go:149 +0x182
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).Run(0xc0003354a0)
        /home/erik/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/driver.go:154 +0x72
fyne.io/fyne/v2/app.(*fyneApp).Run(0xc000335550)
        /home/erik/go/pkg/mod/fyne.io/fyne/[email protected]/app/app.go:72 +0xd0
fyne.io/fyne/v2/internal/driver/glfw.(*window).ShowAndRun(0xc000131a00)
        /home/erik/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/window.go:217 +0x64
main.main()
        /home/erik/go/fyne26-dev/main.go:28 +0x177
exit status 2

@Jacalz
Copy link
Member

Jacalz commented Feb 27, 2025

Strange. Thanks for checking. Seems fine then

@andydotxyz
Copy link
Member

This is now resolved ready for v2.6.0

@andydotxyz andydotxyz added this to the "F" release, Early 2025 milestone Feb 28, 2025
@andydotxyz andydotxyz added bug Something isn't working and removed unverified A bug that has been reported but not verified labels Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants