riking/joycon

The program crashes on start when another non joycon nintendo device exists

aldelaro5 opened this issue ยท 4 comments

I installed the aur package, entered the command sudo jcdriver and I get this:

[console]> panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb8 pc=0x503a2c]

goroutine 1 [running]:
github.com/riking/joycon/prog4/consoleiface.(*Manager).SearchDevices(0xc000086640, 0x0, 0x0)
	/tmp/yaourt-tmp-aldelaro5/aur-joycon-git/src/joycon/prog4/jcdriver/src/github.com/riking/joycon/prog4/consoleiface/Manager.go:448 +0x31c
github.com/riking/joycon/prog4/consoleiface.(*Manager).Run(0xc000086640)
	/tmp/yaourt-tmp-aldelaro5/aur-joycon-git/src/joycon/prog4/jcdriver/src/github.com/riking/joycon/prog4/consoleiface/Manager.go:77 +0x41e
main.main()
	/tmp/yaourt-tmp-aldelaro5/aur-joycon-git/src/joycon/prog4/jcdriver/main.go:49 +0x2c4

Is this expected or have I done something wrong?

EDIT: I have found the cause, it is because the program will try to consider ANY nintendo device as joycons. The reason this was appearing was because I had a wiiu pro paired and it was detecting it as joycons, but didn't get the joycons info so it crash because it tries to print these info which doesn't exist.

Working fine here on Arch

[parker@yoga710 ~]$ sudo jcdriver 
[console]> [INFO] Connected to Joy-Con L 58:2f:40:2d:3e:bc
Joy-Con L (58:2f:40:2d:3e:bc): ๐Ÿ”‹ โ–ˆ 
58:2f:40:2d:3e:bc: Got factory calibration and button colors
58:2f:40:2d:3e:bc: SPI read returned [603d+25]
00000000  d7 84 3c a9 57 8e 88 c4  46 ff ff ff ff ff ff ff  |..<.W...F.......|
00000010  ff ff ff 82 82 82 0f 0f  0f                       |.........|
58:2f:40:2d:3e:bc: SPI read returned [8010+22]
00000000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000010  ff ff ff ff ff ff                                 |......|
58:2f:40:2d:3e:bc: Checked user stick calibration: [{1239 968 1961 2277 1160 1132} {4095 4095 4095 4095 4095 4095}]
[INFO] Connected to Joy-Con R 58:2f:40:32:78:2c
Joy-Con R (58:2f:40:32:78:2c): ๐Ÿ”‹ โ–ˆ 
58:2f:40:32:78:2c: Got factory calibration and button colors
58:2f:40:32:78:2c: SPI read returned [603d+25]
00000000  ff ff ff ff ff ff ff ff  ff 31 28 76 e9 84 45 49  |.........1(v..EI|
00000010  95 43 ff 82 82 82 0f 0f  0f                       |.C.......|
58:2f:40:32:78:2c: SPI read returned [8010+22]
00000000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000010  ff ff ff ff ff ff                                 |......|
58:2f:40:32:78:2c: Checked user stick calibration: [{4095 4095 4095 4095 4095 4095} {1353 1081 2097 1890 1257 1112}]
Plonk! (u0)
Plonk! (u1)
pairing double
set permissions for js3
set permissions for event20

so I eventually got it to run, the problem is I rebooted and then it made the same error, I have no idea how to troubleshoot this one

Okay so this issue is much more clear now as I was very determined to make this work so I tried with a debugger and what I found is that in manager.go, the search device function, it has a switch case with the product id and it doesn't have a default case. This is a problem because say you have another nintendo device like a wiiu pro controller paired (it doesn't even need to be paired, just existing on my end was enough for the program to pick it up), it would assume it was a joycon, but because it wasn't, the information about it aren't initialized so it crash when it tries to print them.

I solved it by simply adding a default case and just do a continue in it. Idk if this is the correct solution, but this hack worked for me. There essentially needs to have a way to not consider any nintendo device that aren't joycons.

Oh, yeah that'd do it...