riking/joycon

Programm crashes when charging-grip is connected via USB

dbaumgarten opened this issue · 0 comments

When i connect the charging-grip via usb (to charge my joycons while using them) the programm crashes on startup when the joycons are connected via bluetooth.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xc0 pc=0x50b09c]

goroutine 1 [running]:
github.com/riking/joycon/prog4/consoleiface.(*Manager).SearchDevices(0xc42008a640, 0x0, 0x0)
	/home/daniel/go/src/github.com/riking/joycon/prog4/consoleiface/Manager.go:449 +0x6dc
github.com/riking/joycon/prog4/consoleiface.(*Manager).Run(0xc42008a640)
	/home/daniel/go/src/github.com/riking/joycon/prog4/consoleiface/Manager.go:77 +0x466
main.main()
	/home/daniel/go/src/github.com/riking/joycon/prog4/jcdriver/main.go:49 +0x32c

The reason seems to that this break:

cancels the for-loop without setting jc to a value.
And the line:

fmt.Println("[INFO] Connected to", jc.Type(), jc.Serial())

will then use jc (which is nil) and crashes.

Replacing the offending break with a continue does prevent the crash, but now the console spams the message "closing uinput 9 10 false".

Replacing the whole case-block for jcpc.JOYCON_PRODUCT_CHARGEGRIP with a continue does also get rid of the crash AND the message-spamming.

I am wondering why there is a block for the charging-grip? Is it more then just a charger? And what is the code in the case-block even supposed to do? Is it safe to remove it?