fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
25.31k stars 1.41k forks source link

app.Run panics if called without window #527

Closed mh-cbon closed 5 years ago

mh-cbon commented 5 years ago

Describe the bug app.Run panics if called without window

To Reproduce

package main

import (
    "flag"
    "fmt"
    _ "image/gif"
    _ "image/jpeg"
    _ "image/png"
    "time"

    "fyne.io/fyne"
    "fyne.io/fyne/app"
    "fyne.io/fyne/canvas"
    "fyne.io/fyne/widget"
)

func main() {

    flag.Parse()
    files := flag.Args()

    i := 0
    a := app.New()
    a.Run()

    for _, file := range files {
        wname := fmt.Sprintf("#%v %v", i, file)
        w := a.NewWindow(wname)
        img := canvas.NewImageFromFile(file)
        img.FillMode = canvas.ImageFillStretch
        img.FillMode = canvas.ImageFillOriginal
        img.FillMode = canvas.ImageFillContain
        scroll := widget.NewScrollContainer(img)
        w.SetContent(scroll)
        w.Canvas().SetOnTypedKey(func(k *fyne.KeyEvent) {
            w.Close()
        })
        w.Show()
        scroll.Resize(fyne.NewSize(400, 400))
        w.Resize(fyne.NewSize(400, 400))
        i++
        <-time.After(time.Second)
    }
    a.Run()
}

results in

$ go run cmd/gv-fyne2/main.go ~/Images/7.png ~/Images/7.png 
panic: NotInitialized: The GLFW library is not initialized

goroutine 1 [running, locked to thread]:
fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.2/glfw.acceptError(0x0, 0x0, 0x0, 0x2, 0xc0000c8078)
    /home/mh-cbon/gow/src/fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.2/glfw/error.go:173 +0x21a
fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.2/glfw.panicError(...)
    /home/mh-cbon/gow/src/fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.2/glfw/error.go:184
fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.2/glfw.PollEvents()
    /home/mh-cbon/gow/src/fyne.io/fyne/vendor/github.com/go-gl/glfw/v3.2/glfw/window.go:778 +0x38
fyne.io/fyne/internal/driver/gl.(*gLDriver).runGL(0xc00009e2a0)
    /home/mh-cbon/gow/src/fyne.io/fyne/internal/driver/gl/loop.go:76 +0x1d5
fyne.io/fyne/internal/driver/gl.(*gLDriver).Run(0xc00009e2a0)
    /home/mh-cbon/gow/src/fyne.io/fyne/internal/driver/gl/driver.go:77 +0x43
fyne.io/fyne/app.(*fyneApp).Run(0xc0000c80a0)
    /home/mh-cbon/gow/src/fyne.io/fyne/app/app.go:52 +0x81
main.main()
    /home/mh-cbon/opencv4/cmd/gv-fyne2/main.go:24 +0x12c
exit status 2

Device (please complete the following information):


$ lsb_release -a && go env && go version && (cd ../gow/src/fyne.io/fyne/ && git rev-parse HEAD)
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: Fedora
Description: Fedora release 31 (Thirty One)
Release: 31
Codename: ThirtyOne
GOARCH="amd64"
GOBIN="/home/mh-cbon/gow/bin"
GOCACHE="/home/mh-cbon/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mh-cbon/gow"
GOPROXY=""
GORACE=""
GOROOT="/home/mh-cbon/.gvm/gos/go1.12.7"
GOTMPDIR=""
GOTOOLDIR="/home/mh-cbon/.gvm/gos/go1.12.7/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build103930905=/tmp/go-build -gno-record-gcc-switches"
go version go1.12.7 linux/amd64
98fc45e
andydotxyz commented 5 years ago

I think this report still applies without the for loop and second app.Run() right?

mh-cbon commented 5 years ago

yes, it does

andydotxyz commented 5 years ago

OK, thanks. This is fixed on "develop" branch ready for our next release. I don't think the patch can be ported back to master as the driver code has diverged and we're putting all our effort into the release due in 2 weeks. If you can switch to the head of develop great, if not then this will be mainline soon.

mh-cbon commented 5 years ago

I moved to develop as suggested, and now it works with this code

One detail though, if i put the resize after the show(), the last image does not show up.

andydotxyz commented 5 years ago

Sorry I missed this detail - can you please test on the latest develop and, if it is still an issue, open a new issue?

Thanks!