gui
gui copied to clipboard
Need clarification on events
package main
import (
"github.com/faiface/gui/win"
"github.com/faiface/mainthread"
"github.com/vova616/screenshot"
"image"
"image/draw"
"time"
)
func run() {
w, err := win.New(win.Title("faiface/gui"), win.Size(800, 600))
if err != nil {
panic(err)
}
redraw := func(drw draw.Image) image.Rectangle {
r := image.Rect(0, 0, 2560, 1440)
img2, _ := screenshot.CaptureScreen()
myImg := image.Image(img2)
draw.Draw(drw, r, myImg, image.ZP, draw.Src)
return r
}
for event := range w.Events() {
switch event.(type) {
case win.WiClose:
close(w.Draw())
default:
time.Sleep(17 * time.Millisecond)
w.Draw() <- redraw
}
}
}
func main() {
mainthread.Run(run)
}
I have coded this example. It grabs a screenshot of my screen and displays it just fine at around 60Hz. It runs for a coupe of seconds until it crashes with the message attached below. I assume im running out of somthing.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x4e00a0]
goroutine 18 [running, locked to thread]:
image.(*RGBA).Bounds(0x54d8de)
/snap/go/9360/src/image/image.go:98
image/draw.clip({0x60e608, 0xc000356000}, 0xc00497be08, {0x60db08, 0x0}, 0xc00497bdc8, {0x0, 0x0}, 0xc00497bde8)
/snap/go/9360/src/image/draw/draw.go:86 +0xd3
image/draw.DrawMask({0x60e608, 0xc000356000}, {{0x0, 0x0}, {0x320, 0x258}}, {0x60db08, 0x0}, {0x0, 0x0}, ...)
/snap/go/9360/src/image/draw/draw.go:117 +0xa5
image/draw.Draw(...)
/snap/go/9360/src/image/draw/draw.go:111
main.run.func1({0x60e608, 0xc000356000})