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

Extending password entry leads to panic when password revealer is clicked #2036

Closed
nick-remeeting opened this issue Feb 26, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@nick-remeeting
Copy link

nick-remeeting commented Feb 26, 2021

Describe the bug:

I want users to be able to submit a username and password with a keypress (enter/return). Following the excellent tutorial on handling keypresses, I was able to do so. However, if the user clicks the password revealer, the app panics due to a segfault:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x41a8d2f]

goroutine 18 [running]:
fyne.io/fyne/v2/internal/app.(*FocusManager).Focus(0x0, 0x4409d00, 0xc000083080, 0x0)
	/Users/nick/go/src/fyne.io/fyne/v2/internal/app/focus_manager.go:25 +0x4f
fyne.io/fyne/v2/internal/driver/glfw.(*glCanvas).Focus(0xc0000b0000, 0x4409d00, 0xc000083080)
	/Users/nick/go/src/fyne.io/fyne/v2/internal/driver/glfw/canvas.go:88 +0x196
fyne.io/fyne/v2/widget.(*passwordRevealer).Tapped(0xc00008e280, 0xc0005748e0)
	/Users/nick/go/src/fyne.io/fyne/v2/widget/entry_password.go:49 +0xc8
fyne.io/fyne/v2/internal/driver/glfw.(*window).mouseClicked.func7()
	/Users/nick/go/src/fyne.io/fyne/v2/internal/driver/glfw/window.go:791 +0x38
fyne.io/fyne/v2/internal/driver/glfw.(*window).runEventQueue(0xc0000a2000)
	/Users/nick/go/src/fyne.io/fyne/v2/internal/driver/glfw/window.go:1242 +0x7a
created by fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).createWindow.func1
	/Users/nick/go/src/fyne.io/fyne/v2/internal/driver/glfw/window.go:1266 +0x10d

It seems that embedding and using an entry with the password revealer causes it to panic on click. I am not sure if this also happens for other ActionItems; I have only tested it in this one case.

To Reproduce:

Run the example code and click each password revealer. The first two (which are not extended/embedded) work fine, but the second two (which are extended/embedded) both cause a panic on click.

Screenshots:

Screen Shot 2021-02-26 at 2 27 29 PM

Example code:

In this example code I don't add any functions to the extended entry -- in the real app there would be a method to handle key presses.

package main

import (
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

type myPasswordEntry struct {
	widget.Entry
}

func newMyPasswordEntry() *myPasswordEntry {
	entry := &myPasswordEntry{
		widget.Entry{
			Password: true,
		},
	}
	entry.ExtendBaseWidget(entry)
	return entry
}

type myOtherPasswordEntry struct {
	*widget.Entry
}

func newMyOtherPasswordEntry() *myOtherPasswordEntry {
	entry := &myOtherPasswordEntry{
		&widget.Entry{
			Password: true,
		},
	}
	entry.ExtendBaseWidget(entry)
	return entry
}

func main() {
	myApp := app.New()
	window := myApp.NewWindow("Example")

	passwordEntry0 := widget.NewPasswordEntry()
	passwordEntry1 := &widget.Entry{Password: true}
	passwordEntry2 := newMyPasswordEntry()
	passwordEntry3 := newMyOtherPasswordEntry()

	passwordEntry0.SetPlaceHolder("Password revealer works")
	passwordEntry1.SetPlaceHolder("This one works too")
	passwordEntry2.SetPlaceHolder("This one crashes")
	passwordEntry3.SetPlaceHolder("This one crashes as well")

	vBox := container.NewVBox(passwordEntry0, passwordEntry1, passwordEntry2, passwordEntry3)

	window.SetContent(vBox)

	window.ShowAndRun()
}

Device (please complete the following information):

  • OS: MacOS
  • Version: 11.2.1
  • Go version: 1.15.7
  • Fyne version: 2.0.0
@nick-remeeting nick-remeeting added the bug Something isn't working label Feb 26, 2021
@Jacalz
Copy link
Member

Jacalz commented Feb 27, 2021

I have not looked at the bug yet, but as a workaround, fyne 2.0.0 and later has the entry.OnSubmit function that you can use directly without having to extend the widget.

@Jacalz
Copy link
Member

Jacalz commented Feb 27, 2021

Just a thought. Does it work if you set entry.Password = true after the entry.ExtendBaseWidget(entry) call in the newMyPasswordEntry function (instead of passing the whole entry in the struct)?

like this, I mean:

entry := &myPasswordEntry{}
entry.ExtendBaseWidget(entry)
entry.Password = true
return entry

This was just a thought I had because I know that extending things in Go can be a bit tricky at times. Might not make any difference.

@andydotxyz
Copy link
Member

andydotxyz commented Feb 27, 2021

This may have been fixed by recent focus work, but I suspect there is a line in our password widget that forgot it may be extended.

@nick-remeeting
Copy link
Author

@Jacalz : I tried your suggestions. Using the entry.OnSubmitted() method works! I'll be using this method in my app, thanks!

I also tried assigning the entry.Password attribute after the entry.ExtendBaseWidget() call as you suggest, and encounter the same bug (I get the same panic as before).

@andydotxyz : Thanks for the info.

Thank you both for your assistance and please do let me know if I can help tracking this bug down.

andydotxyz added a commit to andydotxyz/fyne that referenced this issue Feb 27, 2021
andydotxyz added a commit that referenced this issue Mar 1, 2021
@andydotxyz
Copy link
Member

Fixed on develop, will be in 2.0.1

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