fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design

Home Page:https://fyne.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

when dialog.ShowFileOpen then click cancel,window quit and program terminated

AncestorDragon opened this issue · comments

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

GOVERSION=go1.22.2
fyne.io/fyne/v2 v2.4.5
os: Windows

when dialog.ShowFileOpen then click cancel,window quit and program terminated

How to reproduce

when dialog.ShowFileOpen then click cancel,window quit and program terminated

Screenshots

No response

Example code

button := widget.NewButton("aaa", func() {
	dialog.ShowFileOpen(func(f fyne.URIReadCloser, err error) {
		fmt.Println(f.URI().Path())
		filePath = f.URI().Path()
	}, myWindow)
})

Fyne version

fyne.io/fyne/v2 v2.4.5

Go compiler version

go1.22.2

Operating system and version

Windows

Additional Information

No response

This is not a bug. The documentation for the function (https://pkg.go.dev/fyne.io/fyne/v2/dialog#ShowFileOpen) notes that it will return nil for the file when none is selected. I.e. your application is crashing because you are not checking if f is nil. While likely not the issue here, you will probably run into even more issues given that you aren’t checking the error.