Ref T254, avoid crashes when there is no input device

* init with nullptr
* formatting
This commit is contained in:
Klaus Basan
2018-02-18 00:54:14 +01:00
parent be6b67f95d
commit 602373c97a
2 changed files with 10 additions and 10 deletions

View File

@@ -20,7 +20,6 @@ using namespace BlackMisc::Input;
namespace BlackInput
{
const TCHAR *CJoystickWindows::m_helperWindowClassName = TEXT("HelperWindow");
const TCHAR *CJoystickWindows::m_helperWindowName = TEXT("JoystickCatcherWindow");
ATOM CJoystickWindows::m_helperWindowClass = 0;
@@ -86,6 +85,12 @@ namespace BlackInput
HRESULT CJoystickWindows::enumJoystickDevices()
{
if (!m_directInput)
{
CLogMessage(this).warning("No direct input");
return E_FAIL;
}
HRESULT hr;
if (FAILED(hr = m_directInput->EnumDevices(DI8DEVTYPE_JOYSTICK, enumJoysticksCallback, this, DIEDFL_ATTACHEDONLY)))
{
@@ -145,7 +150,7 @@ namespace BlackInput
HRESULT hr = S_OK;
// Check if device list is empty first
if (m_availableJoystickDevices.isEmpty()) return E_FAIL;
if (m_availableJoystickDevices.isEmpty()) { return E_FAIL; }
// FIXME: Take the first device with number of buttons > 0
// For the future, the user should be able to choose which device

View File

@@ -52,7 +52,6 @@ namespace BlackInput
Q_OBJECT
public:
//! Copy Constructor
CJoystickWindows(CJoystickWindows const &) = delete;
@@ -63,12 +62,10 @@ namespace BlackInput
virtual ~CJoystickWindows();
protected:
//! Timer based updates
virtual void timerEvent(QTimerEvent *event) override;
private:
friend class IJoystick;
//! Constructor
@@ -109,8 +106,8 @@ namespace BlackInput
// todo RW: Try to use QScopedPointer. So far I could not find out how to use it with
// IDirectInput8::CreateDevice
IDirectInput8 *m_directInput; //!< DirectInput object
IDirectInputDevice8 *m_directInputDevice; //!< DirectInput device
IDirectInput8 *m_directInput = nullptr; //!< DirectInput object
IDirectInputDevice8 *m_directInputDevice = nullptr; //!< DirectInput device
QVector<CJoystickDeviceData> m_availableJoystickDevices; //!< List of found and available joystick devices
QVector<CJoystickDeviceInput> m_joystickDeviceInputs; //!< List of available device buttons
@@ -120,9 +117,7 @@ namespace BlackInput
static const WCHAR *m_helperWindowName; //!< Helper window name
static ATOM m_helperWindowClass;
static HWND m_helperWindow; //!< Helper window handle
};
} // namespace BlackInput
#endif // BLACKINPUT_JOYSTICK_WINDOWS_H
#endif // guard