Electronicks / JoyShockMapper

A tool for PC gamers to play games with DualShock 4s, JoyCons, and Pro Controllers. Gyro aiming, flick stick.
Other
362 stars 20 forks source link

Fix linux build errors. #2

Closed mihranmashhud closed 3 years ago

mihranmashhud commented 3 years ago

Did some very minor changes to get the program to build on linux. However, the program segfaults on "QUIT" but I am not sure how to fix it. Seems to be an issue of JslDisconnectAndDisposeAll().

saladuh commented 3 years ago

With your patch it does build on my machine but, as you said, it segfaults. First time using JoyShockMapper, not sure how it's meant to work after launching it but I can't get into the console edit menu as the readme describes. As soon I launch JoyShockMapper, it detects my DS4 controller, loads commands from OnReset.txt and then OnStartup.txt (I added both of these manually, they currently contain the defaults), and then states "Finished executing startup file", then segfaults.

Perhaps I'm misunderstanding what you meant by 'quit' (sorry if I am), but I can't get to the stage where there is even an option to quit. Running Archlinux, kernel 5.11.11, with Sway as my window manager (Wayland), if that means anything here.

mihranmashhud commented 3 years ago

From what I can tell it is likely be an issue with JoyShockLibrary. Will have to investigate it more. I don't have the OnReset.txt and OnStartup.txt files so that is probably why it isn't automatically segfaulting for me. Will add those in and see what methods segfault using valgrind and will then post the output here if anyone else wants to investigate the issue.

mihranmashhud commented 3 years ago

Here is the valgrind output for when inputting the QUIT command without any OnStartup.txt or OnReset.txt.

==186289== Memcheck, a memory error detector
==186289== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==186289== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==186289== Command: JoyShockMapper/JoyShockMapper
==186289== 
Welcome to JoyShockMapper version v3.0.0!
AUTOLOAD is enabled. Files in /home/mihranmashhud/.config/JoyShockMapper/AutoLoad/ folder will get loaded automatically when a matching application is in focus.
[AUTOLOAD] "zsh" in focus: create AutoLoad\kitty.txt to autoload for this application.
DS4
DS
1 device connected
==186289== Thread 3:
==186289== Conditional jump or move depends on uninitialised value(s)
==186289==    at 0x125B1F: GamepadMotion::ProcessMotion(float, float, float, float, float, float, float) (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x129E39: joyShockPollCallback(int, JOY_SHOCK_STATE, JOY_SHOCK_STATE, IMU_STATE, IMU_STATE, float) (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x28D225: pollIndividualLoop(JoyShock*) (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x296241: void std::__invoke_impl<void, void (*)(JoyShock*), JoyShock*>(std::__invoke_other, void (*&&)(JoyShock*), JoyShock*&&) (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x296191: std::__invoke_result<void (*)(JoyShock*), JoyShock*>::type std::__invoke<void (*)(JoyShock*), JoyShock*>(void (*&&)(JoyShock*), JoyShock*&&) (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x296154: void std::thread::_Invoker<std::tuple<void (*)(JoyShock*), JoyShock*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x296104: std::thread::_Invoker<std::tuple<void (*)(JoyShock*), JoyShock*> >::operator()() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x295FAD: std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(JoyShock*), JoyShock*> > >::_M_run() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x58ADBC3: execute_native_thread_routine (thread.cc:80)
==186289==    by 0x57B6298: start_thread (in /usr/lib/libpthread-2.33.so)
==186289==    by 0x5C19052: clone (in /usr/lib/libc-2.33.so)
==186289== 
Resetting all mappings to defaults
There is no OnReset.txt file to load.
There is no OnStartup.txt file to load.
--186289-- WARNING: unhandled amd64-linux syscall: 315
--186289-- You may be able to write your own handler.
--186289-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--186289-- Nevertheless we consider this a bug.  Please report
--186289-- it at http://valgrind.org/support/bug_reports.html.

(JoyShockMapper:186289): Gdk-CRITICAL **: 17:16:00.327: gdk_window_thaw_toplevel_updates: assertion 'window->update_and_descendants_freeze_count > 0' failed
QUIT
vex amd64->IR: unhandled instruction bytes: 0x7 0x0 0x0 0x0 0x0 0x58 0x2D 0x94 0x7 0x0
vex amd64->IR:   REX=0 REX.W=0 REX.R=0 REX.X=0 REX.B=0
vex amd64->IR:   VEX=0 VEX.L=0 VEX.nVVVV=0x0 ESC=NONE
vex amd64->IR:   PFX.66=0 PFX.F2=0 PFX.F3=0
==186289== Thread 1:
==186289== Invalid read of size 1
==186289==    at 0x7942D30: ???
==186289==    by 0x184C89: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x184B8D: std::__shared_ptr<DigitalButton::Common, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x148317: std::shared_ptr<DigitalButton::Common>::~shared_ptr() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x202765: JoyShock::~JoyShock() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x28DF6F: JslDisconnectAndDisposeAll (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x13254B: CleanUp() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x13E57B: main (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==  Address 0x69ec90 is not stack'd, malloc'd or (recently) free'd
==186289== 
==186289== 
==186289== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==186289==  Access not within mapped region at address 0x69EC90
==186289==    at 0x7942D30: ???
==186289==    by 0x184C89: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x184B8D: std::__shared_ptr<DigitalButton::Common, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x148317: std::shared_ptr<DigitalButton::Common>::~shared_ptr() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x202765: JoyShock::~JoyShock() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x28DF6F: JslDisconnectAndDisposeAll (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x13254B: CleanUp() (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==    by 0x13E57B: main (in /home/mihranmashhud/Documents/Coding/joyshockmapper/fork/build/JoyShockMapper/JoyShockMapper)
==186289==  If you believe this happened as a result of a stack
==186289==  overflow in your program's main thread (unlikely but
==186289==  possible), you can try to increase the size of the
==186289==  main thread stack using the --main-stacksize= flag.
==186289==  The main thread stack size used in this run was 8388608.
==186289== 
==186289== HEAP SUMMARY:
==186289==     in use at exit: 3,145,589 bytes in 35,141 blocks
==186289==   total heap usage: 418,169 allocs, 383,028 frees, 27,384,050 bytes allocated
==186289== 
==186289== LEAK SUMMARY:
==186289==    definitely lost: 3,267 bytes in 16 blocks
==186289==    indirectly lost: 15,796 bytes in 645 blocks
==186289==      possibly lost: 5,124 bytes in 27 blocks
==186289==    still reachable: 2,905,610 bytes in 32,622 blocks
==186289==         suppressed: 1,112 bytes in 1 blocks
==186289== Rerun with --leak-check=full to see details of leaked memory
==186289== 
==186289== Use --track-origins=yes to see where uninitialised values come from
==186289== For lists of detected and suppressed errors, rerun with: -s
==186289== ERROR SUMMARY: 6360 errors from 2 contexts (suppressed: 0 from 0)
zsh: segmentation fault (core dumped)  valgrind JoyShockMapper/JoyShockMapper
saladuh commented 3 years ago

My bad, I should have clarified that I still segfault automatically without the OnStartup.txt and OnReset.txt files. It still segfaults with 0 configuration, as it did the first time I launched it.

The first few times I launched joyshockmapper while trying to see if I could get it to stop segfaulting, I kept getting an error about failing to find a window, which is why I mentioned that I'm on Wayland because I thought it might be the issue. Unfortunately, when I went to copy the exact error to post it here, the error suddenly stopped happening all together (but the program still segfaults automatically). As far as I can tell there's no logs either.

(I should have mentioned all these things in my original comment, sorry, I really shouldn't report issues on GitHub at 4 am lol)

Edit: maybe the automatic segfaulting I'm experiencing isn't a Linux specific issue? See https://github.com/JibbSmart/JoyShockMapper/issues/155

mihranmashhud commented 3 years ago

Think you may be right on it not being linux specific.

mihranmashhud commented 3 years ago

Would be nice if we had CI testing as this project is starting to get big enough that it feels like it calls for it.

Electronicks commented 3 years ago

Ah yup... I want to add unit tests using gtest/gmock. That should help a lot. I have a few changes coming up soon that will affect the linux build. I'm hoping to get them in quick for you guys to help with the build smoke until I get a linux set up myself.

Thanks for the valgrind run. That will be useful to debug.