Skip to content

Segfault when adding items directly in form struct #3153

Closed
@paupin2

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

I get a SEGFAULT when calling .Refresh() on a form where all items were all added in the struct creation.

I followed this example, but added everything as Items when creating the struct -- so no form.Append().

This issue may be the same as #1967, but I'm not sure.

The problem seems to be when ensureRenderItems assumes itemGrid is not null. This is not the case when adding items directly to the form struct.

If adding items directly is not recommended, maybe the tutorial could be updated.
But a guard on this code would probably be safer.

How to reproduce

Call start(false) on the example code below and it works fyne.
Call start(true) on and it segfaults.

Screenshots

No response

Example code

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

func start(segfault bool) {
	a := app.New()
	w := a.NewWindow("Manny")

	name := widget.NewEntry()
	name.SetPlaceHolder("John Smith")
	item := &widget.FormItem{Text: "Name", Widget: name}

	form := &widget.Form{}
	if segfault {
		form.Items = []*widget.FormItem{item}
	} else {
		form.AppendItem(item)
	}
	form.Refresh()

	w.SetContent(form)
	w.ShowAndRun()
}

Fyne version

v2.2.3

Go compiler version

go1.18.4

Operating system

macOS

Operating system version

11.6.5

Additional Information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    unverifiedA bug that has been reported but not verified

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions