sourcegraph / go-webkit2

WebKit API bindings (WebKitGTK+ v2) for Go
https://sourcegraph.com/github.com/sourcegraph/go-webkit2
Other
313 stars 61 forks source link

Panic on .GetSnapshot #16

Closed pzduniak closed 8 years ago

pzduniak commented 9 years ago
import (
    "bytes"
    "image"
    "image/png"
    "log"
    "runtime"

    "github.com/conformal/gotk3/glib"
    "github.com/conformal/gotk3/gtk"
    "github.com/dchest/uniuri"
    "github.com/sourcegraph/go-webkit2/webkit2"
)

func init() {
    gtk.Init(nil)
    go func() {
        runtime.LockOSThread()
        gtk.Main()
    }()
}

func RasterizeURI(uri string, width int, height int) ([]byte, error) {
    log.Print(uri)

    webViewChan := make(chan *webkit2.WebView, 1)

    glib.IdleAdd(func() bool {
        webView := webkit2.NewWebView()
        webViewChan <- webView

        return false
    })

    webView := <-webViewChan

    defer webView.Destroy()

    resultChan := make(chan []byte, 1)
    errChan := make(chan error, 1)

    webView.Connect("load-changed", func(_ *glib.Object, loadEvent webkit2.LoadEvent) {
        switch loadEvent {
        case webkit2.LoadFinished:
            webView.GetSnapshot(func(img *image.RGBA, err error) {
                if err != nil {
                    log.Print("ERR; SENDING PREMATURELY")
                    errChan <- err
                }

                buf := new(bytes.Buffer)
                err = png.Encode(buf, img)

                log.Printf("%s: %s", uri, "SENDING TO CHAN RESULT")
                errChan <- err
                resultChan <- buf.Bytes()
            })
        }
    })

    log.Print("INSIDE RASTERIZEURI")

    glib.IdleAdd(func() bool {
        log.Print("INSIDE IDLEADD")

        webView.LoadURI(uri)

        return false
    })

    log.Print("LOCKING ON ERRCHAN")

    err := <-errChan
    if err != nil {
        return nil, err
    }

    log.Print("LOCKING ON DATACHAN")

    data := <-resultChan

    log.Print("SUCCESS")

    // Return the contents of the result file
    return data, nil
}
panic: reflect: call of reflect.Value.Call on int32 Value

goroutine 5 [running]:
reflect.flag.mustBe(0x5, 0x13)
    /usr/local/go/src/reflect/value.go:195 +0xb8
reflect.Value.Call(0xc2080fc0d0, 0x1, 0x5, 0xc208acbe88, 0x1, 0x1, 0x0, 0x0, 0x0)
    /usr/local/go/src/reflect/value.go:294 +0x55
github.com/sourcegraph/go-webkit2/webkit2._go_gasyncreadycallback_call(0xc2087f43a0, 0x7f9fc4003ab0)
    /home/kernal/gopath/src/github.com/sourcegraph/go-webkit2/webkit2/gasyncreadycallback.go:20 +0x124
github.com/conformal/gotk3/gtk._Cfunc_gtk_main()
    /home/kernal/gopath/src/github.com/conformal/gotk3/gtk/:2843 +0x45
github.com/conformal/gotk3/gtk.Main()
    /home/kernal/gopath/src/github.com/conformal/gotk3/gtk/gtk.go:766 +0x1b
[masked].func·001()
    [masked]:25 +0x1b
created by [masked].init·1
    [masked]:26 +0x36

The "reflect.Value.Call on x Value" is different with every run, x changes to various strings: int32, Value, sometimes the error is:

panic: reflect: NumIn of non-func type

goroutine 5 [running]:
reflect.(*rtype).NumIn(0xc2087f6bc0, 0x0)
    /usr/local/go/src/reflect/type.go:665 +0x7a
reflect.Value.call(0xc2087f6bc0, 0xdeaddeaddeaddead, 0x13, 0xadf4e0, 0x4, 0xc2083d1e88, 0x1, 0x1, 0x0, 0x0, ...)
    /usr/local/go/src/reflect/value.go:336 +0x1e3
reflect.Value.Call(0xc2087f6bc0, 0xdeaddeaddeaddead, 0x13, 0xc2083d1e88, 0x1, 0x1, 0x0, 0x0, 0x0)
    /usr/local/go/src/reflect/value.go:296 +0xbc
github.com/sourcegraph/go-webkit2/webkit2._go_gasyncreadycallback_call(0xc2087f6ba0, 0x7f3fd4003a70)
    /home/kernal/gopath/src/github.com/sourcegraph/go-webkit2/webkit2/gasyncreadycallback.go:20 +0x124
github.com/conformal/gotk3/gtk._Cfunc_gtk_main()

That seems to happen after two WebViews were created and destroyed. The third one seems to crash (out of 4 spawned).

Ramshackle-Jamathon commented 8 years ago

I was running into this error before we moved from conformal/gotk to gotk/gotk.

Since then I have not run into this weird issue.

sqs commented 8 years ago

I will close this based on @Ramshackle-Jamathon's report. Please let me know if you are still experiencing it, and I will reopen it.