Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request xbmc#770 from CrystalP/fix-joycrash
Browse files Browse the repository at this point in the history
[WIN] fix joystick connect/disconnect issues.
  • Loading branch information
CrystalP committed Mar 18, 2012
2 parents c317d94 + 31e0ce9 commit 0692d0b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
20 changes: 20 additions & 0 deletions xbmc/input/SDLJoystick.cpp
Expand Up @@ -408,4 +408,24 @@ float CJoystick::SetDeadzone(float val)
return val;
}

bool CJoystick::Reinitialize()
{
// Restart SDL joystick subsystem
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
if (SDL_WasInit(SDL_INIT_JOYSTICK) != 0)
{
CLog::Log(LOGERROR, "Stop joystick subsystem failed");
return false;
}
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0)
{
CLog::Log(LOGERROR, "Restart joystick subsystem failed : %s",SDL_GetError());
return false;
}

Initialize();

return true;
}

#endif
1 change: 1 addition & 0 deletions xbmc/input/SDLJoystick.h
Expand Up @@ -64,6 +64,7 @@ class CJoystick
float GetAmount(int axis);
float GetAmount() { return GetAmount(m_AxisId); }
float SetDeadzone(float val);
bool Reinitialize();

private:
void SetAxisActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_AXIS):(m_ActiveFlags&(~JACTIVE_AXIS)); }
Expand Down
27 changes: 4 additions & 23 deletions xbmc/linux/HALManager.cpp
Expand Up @@ -511,19 +511,9 @@ void CHALManager::AddDevice(const char *udi)
if(m_Joysticks.size() < 2 || m_bMultipleJoysticksSupport)
{
// Restart SDL joystick subsystem
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
if (SDL_WasInit(SDL_INIT_JOYSTICK) != 0)
{
CLog::Log(LOGERROR, "HAL: Stop joystick subsystem failed");
break;
}
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0)
{
CLog::Log(LOGERROR, "HAL: Restart joystick subsystem failed : %s",SDL_GetError());
if (!g_Joystick.Reinitialize())
break;
}

g_Joystick.Initialize();
if (m_Notifications)
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(13024), dev.FriendlyName.c_str(), TOAST_DISPLAY_TIME, false);
}
Expand Down Expand Up @@ -576,20 +566,11 @@ bool CHALManager::RemoveDevice(const char *udi)
if(m_Joysticks.size() < 3 || m_bMultipleJoysticksSupport)
{
// Restart SDL joystick subsystem
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
if (SDL_WasInit(SDL_INIT_JOYSTICK) != 0)
{
CLog::Log(LOGERROR, "HAL: Stop joystick subsystem failed");
if (!g_Joystick.Reinitialize())
return false;
}
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0)
{
CLog::Log(LOGERROR, "HAL: Restart joystick subsystem failed : %s",SDL_GetError());
return false;
}

g_Joystick.Initialize();
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning, g_localizeStrings.Get(13025), m_Joysticks[i].FriendlyName.c_str(), TOAST_DISPLAY_TIME, false);
if (m_Notifications)
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning, g_localizeStrings.Get(13025), m_Joysticks[i].FriendlyName.c_str(), TOAST_DISPLAY_TIME, false);
}
m_Joysticks.erase(m_Joysticks.begin() + i);
return true;
Expand Down
8 changes: 8 additions & 0 deletions xbmc/windowing/windows/WinEventsWin32.cpp
Expand Up @@ -27,6 +27,9 @@
#include "Application.h"
#include "input/XBMC_vkeys.h"
#include "input/MouseStat.h"
#if defined(HAS_SDL_JOYSTICK)
#include "input/SDLJoystick.h"
#endif
#include "storage/MediaManager.h"
#include "windowing/WindowingFactory.h"
#include <dbt.h>
Expand Down Expand Up @@ -688,7 +691,12 @@ LRESULT CALLBACK CWinEventsWin32::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, L
case DBT_DEVICEARRIVAL:
case DBT_DEVICEREMOVECOMPLETE:
if (((_DEV_BROADCAST_HEADER*) lParam)->dbcd_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
{
g_peripherals.TriggerDeviceScan(PERIPHERAL_BUS_USB);
#if defined(HAS_SDL_JOYSTICK)
g_Joystick.Reinitialize();
#endif
}
}
break;
}
Expand Down

0 comments on commit 0692d0b

Please sign in to comment.