Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program crashes when using hook.End() #4

Open
moson-mo opened this issue Aug 29, 2019 · 1 comment
Open

Program crashes when using hook.End() #4

moson-mo opened this issue Aug 29, 2019 · 1 comment

Comments

@moson-mo
Copy link

moson-mo commented Aug 29, 2019

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.

@dachinat
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants