Skip to content

Commit

Permalink
fix: Replace SDL controller calls with joystick ones in Joystick.
Browse files Browse the repository at this point in the history
This is enough of a fix to resolve the issue in AntiMicroX#632, but there are a few other edge cases that investigation brought up that may cause a similar issue in the future.
  • Loading branch information
nitz committed Dec 17, 2022
1 parent 1ed97ca commit 1841e37
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ QString Joystick::getVendorString() const
{
QString temp = QString();

if (controller != nullptr)
if (m_joyhandle != nullptr)
{
Uint16 tempVendor = SDL_GameControllerGetVendor(controller);
Uint16 tempVendor = SDL_JoystickGetVendor(m_joyhandle);
char buffer[50];
sprintf(buffer, "%u", tempVendor);

Expand All @@ -93,9 +93,9 @@ QString Joystick::getProductIDString() const
{
QString temp = QString();

if (controller != nullptr)
if (m_joyhandle != nullptr)
{
Uint16 tempProduct = SDL_GameControllerGetProduct(controller);
Uint16 tempProduct = SDL_JoystickGetProduct(m_joyhandle);
char buffer[50];
sprintf(buffer, "%u", tempProduct);

Expand All @@ -109,26 +109,23 @@ QString Joystick::getSerialString() const
{
QString temp = QString();
#if SDL_VERSION_ATLEAST(2, 0, 14)
if (controller != nullptr)
if (m_joyhandle != nullptr)
{
SDL_Joystick *joyhandle = SDL_GameControllerGetJoystick(controller);
if (joyhandle != nullptr)
{
const char *serial = SDL_JoystickGetSerial(joyhandle);
temp = QString(serial).remove(QRegExp("[^A-Za-z0-9]"));
}
const char *serial = SDL_JoystickGetSerial(m_joyhandle);
temp = QString(serial).remove(QRegExp("[^A-Za-z0-9]"));
}
#endif

return temp;
}

QString Joystick::getProductVersion() const
{
QString temp = QString();

if (controller != nullptr)
if (m_joyhandle != nullptr)
{
Uint16 tempProductVersion = SDL_GameControllerGetProductVersion(controller);
Uint16 tempProductVersion = SDL_JoystickGetProductVersion(m_joyhandle);
char buffer[50];
sprintf(buffer, "%u", tempProductVersion);

Expand Down

0 comments on commit 1841e37

Please sign in to comment.