Description
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
A nil pointer dereference occurs when resizing a color picker dialog.
This only seems to only happen without setting an initial color with colorPicker.SetColor(c)
.
The real nil pointer occurs in popup.go
.
It can be worked around with calling colorPicker.Refresh()
before resizing.
How to reproduce
- Create a color picker dialog (
cp
). - Do not set the initial color with
cp.SetColor()
. - Call
cp.Resize()
- Call
cp.Show()
Do the steps 1. to 4. again but with the second step modified to:
2. Do set set the initial color with cp.SetColor()
.
The third step (Resize) will crash the app.
Screenshots
No response
Example code
package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/dialog"
"image/color"
"os"
)
func main() {
fapp := app.NewWithID("app-with-unique-id")
win := fapp.NewWindow("pick color")
win.Resize(fyne.NewSize(500, 500))
cp := dialog.NewColorPicker("", "", func(c color.Color) {
fmt.Println("Color callback called!")
win.Close()
fapp.Quit()
}, win)
if len(os.Args) >= 2 && os.Args[1] == "1" {
cp.Advanced = true
cp.SetColor(color.White)
}
if len(os.Args) >= 3 && os.Args[2] == "2" {
cp.Refresh() // update the picker internal UI
}
cp.Resize(fyne.NewSize(500, 500)) // this might crash!!!
cp.Show()
win.Show()
fapp.Run()
}
Fyne version
2.5.2
Go compiler version
1.23.1
Operating system and version
Linux 6.1.0-26-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.112-1 (2024-09-30) x86_64 GNU/Linux
Additional Information
The fix is rather simple.
Just call p.updateUI()
in an own Resize
method for the color picker before calling the base dialogs Resize
method.
That will fill p.win
and so prevent win
from being nil
.
I would be happy to provide a pull request.
Activity