zserge / lorca

Build cross-platform modern desktop apps in Go + HTML5
MIT License
8.04k stars 535 forks source link

Bug: nil pointer interface. #40

Closed oytunistrator closed 5 years ago

oytunistrator commented 5 years ago

I take nil pointer interface in Mac OS X:

installation:

$ go get -v github.com/zserge/lorca
github.com/zserge/lorca (download)
Fetching https://golang.org/x/net/websocket?go-get=1
Parsing meta tags from https://golang.org/x/net/websocket?go-get=1 (status code 200)
get "golang.org/x/net/websocket": found meta tag get.metaImport{Prefix:"golang.org/x/net", VCS:"git", RepoRoot:"https://go.googlesource.com/net"} at h
ttps://golang.org/x/net/websocket?go-get=1
get "golang.org/x/net/websocket": verifying non-authoritative meta tag
Fetching https://golang.org/x/net?go-get=1
Parsing meta tags from https://golang.org/x/net?go-get=1 (status code 200)
golang.org/x/net (download)
golang.org/x/net/websocket
github.com/zserge/lorca

sample code:

package main

import (
        "fmt"
    "github.com/zserge/lorca"
)

func main() {
    ui, _ := lorca.New("", "", 480, 320)  # <---- ui is nil pointer interface!
    fmt.Printf("%v\n", ui) 
    defer ui.Close()
}

result:

$ go run -v testcase8.go
command-line-arguments
<nil>
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x12b0c09]

goroutine 1 [running]:
main.main()
        /test/testcase8.go:15 +0xd9
exit status 2
kunalpowar commented 5 years ago

You should handle the err returned by lorca.New. The error will tell you why it could not create a UI in the first place.

ui, err := lorca.New("", "", 480, 320)
if err != nil {
    log.Fatal(err)
}