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

panic if app.New() is not the first method called. #4781

Closed
2 tasks done
williammoran opened this issue Apr 11, 2024 · 2 comments
Closed
2 tasks done

panic if app.New() is not the first method called. #4781

williammoran opened this issue Apr 11, 2024 · 2 comments
Labels
unverified A bug that has been reported but not verified

Comments

@williammoran
Copy link

williammoran commented Apr 11, 2024

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

This code panics. I have no explanation for why it would panic. However, moving app.New() to the top of main() allows it to work. Anything to make this requirement clearer would be helpful.

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

goroutine 7 [running]:
fyne.io/fyne/v2/app.(*settings).Theme(0x188c420?)
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/app/settings.go:66 +0x29
fyne.io/fyne/v2/theme.current()
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/theme/theme.go:179 +0x31
fyne.io/fyne/v2/theme.InnerPadding()
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/theme/size.go:91 +0x13
fyne.io/fyne/v2/widget.(*RichText).updateRowBounds(0xc000406000)
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/widget/richtext.go:362 +0x27
fyne.io/fyne/v2/widget.NewRichText(...)
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/widget/richtext.go:57
fyne.io/fyne/v2/widget.NewRichTextWithText({0xbb6eb1, 0x38})
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/widget/richtext.go:66 +0x13d
fyne.io/fyne/v2/widget.(*Label).CreateRenderer(0xc000400000)
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/widget/label.go:69 +0x27
fyne.io/fyne/v2/internal/cache.Renderer({0xcc2310, 0xc000400000})
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/internal/cache/widget.go:33 +0x118
fyne.io/fyne/v2/widget.(*Label).MinSize(0xc000400000)
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/widget/label.go:93 +0x3b
fyne.io/fyne/v2/widget.(*List).CreateRenderer(0xc000000240)
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/widget/list.go:83 +0x6b
fyne.io/fyne/v2/internal/cache.Renderer({0xcc22a8, 0xc000000240})
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/internal/cache/widget.go:33 +0x118
fyne.io/fyne/v2/widget.(*BaseWidget).Refresh(0x0?)
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/widget/widget.go:138 +0x1d
fyne.io/fyne/v2/data/binding.(*listener).DataChanged(0x1?)
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/data/binding/binding.go:56 +0x12
fyne.io/fyne/v2/data/binding.queueItem.func1.1()
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/data/binding/queue.go:19 +0x3c
created by fyne.io/fyne/v2/data/binding.queueItem.func1 in goroutine 1
	/home/wmoran/go/pkg/mod/fyne.io/fyne/v2@v2.4.4/data/binding/queue.go:17 +0x46

How to reproduce

build+run the code

Screenshots

No response

Example code

package main

import (
	"fmt"

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

var l0Items []string

func main() {
	for c := 0; c < 10; c++ {
		l0Items = append(l0Items, fmt.Sprintf("L0 Item %d", c))
	}
	const widthString = "Really Long String to try to force the width to be wider"
	listBinding := binding.BindStringList(&l0Items)
	l0 := widget.NewListWithData(
		listBinding,
		func() fyne.CanvasObject {
			return widget.NewLabel(widthString)
		},
		func(i binding.DataItem, o fyne.CanvasObject) {
			o.(*widget.Label).Bind(i.(binding.String))
		},
	)
	layout := container.New(layout.NewVBoxLayout(), l0)
	a := app.New()
	w := a.NewWindow("Experiment")
	w.SetContent(layout)
	w.ShowAndRun()
}

Fyne version

v2.4.4

Go compiler version

go version go1.22.1 linux/amd64

Operating system and version

Ubuntu 22

Additional Information

No response

@williammoran williammoran added the unverified A bug that has been reported but not verified label Apr 11, 2024
@andydotxyz
Copy link
Member

With the attached PR you now get the following instead of a crash:

2024/04/23 10:21:16 Fyne error:  Attempt to access current Fyne theme when no app is started
2024/04/23 10:21:16   At: /Users/andy/Code/Fyne/fyne/app/settings.go:70

@andydotxyz
Copy link
Member

This is now resolved on develop branch and will be in v2.5.0

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

2 participants