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

Nil dereference in button renderer when Icon field is set directly #1553

Closed
drognisep opened this issue Nov 15, 2020 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@drognisep
Copy link
Contributor

Describe the bug:

When a button's Icon field is set directly instead of through SetIcon, then it effectively cannot be disabled due to a nil dereference of b.button.disabledIcon in the renderer.

To Reproduce:

Steps to reproduce the behaviour:

  1. Create a button by setting the Icon field directly.
  2. Disable the button by calling theButton.Disable().

Where the crash happens:

func (b *buttonRenderer) Refresh() {
 /* ... */
			if b.button.Disabled() {
				// if the icon has changed, create a new disabled version
				// if we could be sure that button.Icon is only ever set through the button.SetIcon method, we could remove this
				if !strings.HasSuffix(b.button.disabledIcon.Name(), b.button.Icon.Name()) { // <<< boom
					b.icon.Resource = theme.NewDisabledResource(b.button.Icon)
				} else {
					b.icon.Resource = b.button.disabledIcon
				}
			} else {
				b.icon.Resource = b.button.Icon
			}
/* ... */
}

Example code:

func main() {
    myApp := app.New()
    win := myApp.NewWindow("Testing bug")

    var crashButton *widget.Button
    crashButton = &widget.Button{
        Text:       "Crash",
        Icon:       theme.ConfirmIcon(),
        Importance: widget.HighImportance,
        OnTapped: func() {
            crashButton.Disable() // <<< bombs in renderer
        },
    }
    content := fyne.NewContainerWithLayout(layout.NewVBoxLayout(),
        layout.NewSpacer(), crashButton, layout.NewSpacer(),
    )
    time.AfterFunc(1 * time.Second, func() {
        dialog.ShowCustom("Testing bug", "Don't crash", content, win)
    })
    win.ShowAndRun()
}

Device (please complete the following information):

  • OS: Windows 10
  • Version: 2004 build 19041.630
  • Go version: go version go1.15.3 windows/amd64
  • Fyne version: 1.4.0
@Jacalz Jacalz added the bug Something isn't working label Nov 16, 2020
andydotxyz added a commit to andydotxyz/fyne that referenced this issue Nov 16, 2020
Also fixes issues with disabled handling in button and select_entry
.
Fixes fyne-io#1553
@andydotxyz
Copy link
Member

On release/v1.4.x for testing

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