gohook icon indicating copy to clipboard operation
gohook copied to clipboard

Program crashes when using hook.End()

Open moson-mo opened this issue 5 years ago • 1 comments

Hi,

Sometimes when calling hook.End() the program is crashing (not always).

double free or corruption (out)
SIGABRT: abort
PC=0x7ff0e767e755 m=6 sigcode=18446744073709551610

Small example app which should reproduce the issue: Seems crashing is more likely when the mouse is moved around while it is running.


func main() {
	events := hook.Start()

	go func() {
		for {
			event := <-events
			fmt.Println(event)
		}
	}()

	go func() {
		for {
			time.Sleep(100 * time.Millisecond)
			hook.End()
			time.Sleep(100 * time.Millisecond)
			hook.Start()
		}
	}()

	reader := bufio.NewReader(os.Stdin)
	for {
		input, _ := reader.ReadString('\n')
		input = strings.Replace(input, "\n", "", -1)

		if input == "quit" {
			hook.End()
			break
		}
	}
}

Running on linux, so X11.

moson-mo avatar Aug 29 '19 15:08 moson-mo

Having same problem running on Linux X11

func mouse(rect *canvas.Rectangle, data *[]string, list *widget.List, btn *widget.Button, btn2 *widget.Button) {

	hook.Register(hook.MouseMove, []string{}, func(e hook.Event) {
		// ...
	})

	hook.Register(hook.MouseDown, []string{}, func(e hook.Event) {
		c := robotgo.GetPixelColor(int(e.X), int(e.Y))
		*data = append(*data, c)
		hook.End()
	})

	s := hook.Start()
	<-hook.Process(s)
}

This function gets invoked on a button click; If I try to click on button consecutively program crashes (using Fyne):

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x7f07d67c5240]

runtime stack:
runtime.throw({0xb94904?, 0x6d?})
	/usr/lib/go-1.18/src/runtime/panic.go:992 +0x71
runtime.sigpanic()
	/usr/lib/go-1.18/src/runtime/signal_unix.go:802 +0x3a9

goroutine 179 [syscall]:
runtime.cgocall(0xa29a20, 0xc0000bde08)
	/usr/lib/go-1.18/src/runtime/cgocall.go:157 +0x5c fp=0xc0000bdde0 sp=0xc0000bdda8 pc=0x42ecfc
github.com/robotn/gohook._Cfunc_stop_event()
	_cgo_gotypes.go:138 +0x48 fp=0xc0000bde08 sp=0xc0000bdde0 pc=0xa1e2a8
github.com/robotn/gohook.End()
	/home/dachi/go/pkg/mod/github.com/robotn/[email protected]/hook.go:247 +0x37 fp=0xc0000bde30 sp=0xc0000bde08 pc=0xa1f437
main.mouse.func2({0x8, {0xc112eb2c66971430, 0x18158c65e, 0x139f440}, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, ...})
	/home/dachi/Code/go-colorpicker/main.go:103 +0x1c5 fp=0xc0000bdeb8 sp=0xc0000bde30 pc=0xa20dc5
github.com/robotn/gohook.Process.func1()
	/home/dachi/go/pkg/mod/github.com/robotn/[email protected]/hook.go:147 +0x26f fp=0xc0000bdfe0 sp=0xc0000bdeb8 pc=0xa1e8af
runtime.goexit()
	/usr/lib/go-1.18/src/runtime/asm_amd64.s:1571 +0x1 fp=0xc0000bdfe8 sp=0xc0000bdfe0 pc=0x48f0a1
created by github.com/robotn/gohook.Process
	/home/dachi/go/pkg/mod/github.com/robotn/[email protected]/hook.go:133 +0xad

dachinat avatar May 22 '23 09:05 dachinat