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

Develop: App freezes when calling (binding.StringList).Append() from goroutine #5464

Closed
2 tasks done
roffe opened this issue Jan 25, 2025 · 1 comment
Closed
2 tasks done
Labels
unverified A bug that has been reported but not verified

Comments

@roffe
Copy link
Contributor

roffe commented Jan 25, 2025

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

App freezes when binding.Append called from Goroutine

Providing example code to trigger it. Latest develop, migrations enabled

How to reproduce

Run provided example code and press "crash" button

Screenshots

No response

Example code

package main

import (
	"log"
	"time"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/data/binding"
	"fyne.io/fyne/v2/widget"
)

func init() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
}

func main() {
	app := app.New()
	w := app.NewWindow("Hello")

	outputData := binding.NewStringList()

	output := widget.NewListWithData(
		outputData,
		func() fyne.CanvasObject {
			w := widget.NewLabel("")
			w.Alignment = fyne.TextAlignLeading
			w.Truncation = fyne.TextTruncateEllipsis
			return w
		},
		func(item binding.DataItem, obj fyne.CanvasObject) {
			i := item.(binding.String)
			txt, err := i.Get()
			if err != nil {
				fyne.LogError("Failed to get string", err)
				return
			}
			obj.(*widget.Label).SetText(txt)
		},
	)

	l := binding.NewDataListener(func() {
		output.ScrollToBottom()
	})
	outputData.AddListener(l)

	w.SetContent(container.NewBorder(
		widget.NewLabel("Hello Fyne!"),
		container.NewGridWithColumns(2,
			widget.NewButton("Crash", func() {
				go func() {
					time.Sleep(200 * time.Millisecond)
					outputData.Append("Hello")
				}()
			}),
			widget.NewButton("No crash", func() {
				go func() {
					time.Sleep(200 * time.Millisecond)
					fyne.Do(func() {
						outputData.Append("i am alive")
					})
				}()
			}),
		),
		nil,
		nil,
		output,
	))
	w.ShowAndRun()
}

Fyne version

Develop

Go compiler version

1.23.5

Operating system and version

Windows 11 24H2

Additional Information

No response

@roffe roffe added the unverified A bug that has been reported but not verified label Jan 25, 2025
@roffe
Copy link
Contributor Author

roffe commented Jan 25, 2025

Fixed by #5461

@roffe roffe closed this as completed Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unverified A bug that has been reported but not verified
Projects
None yet
Development

No branches or pull requests

1 participant