Commit ea60e467 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dinput: Return DIERR_INPUTLOST when device is removed.

This fixes hotplug with DS4 and other DInput-compatible controllers in Tekken 7. Signed-off-by: 's avatarRémi Bernon <rbernon@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 3039fd6d
......@@ -1553,7 +1553,9 @@ static HRESULT WINAPI dinput_device_GetDeviceState( IDirectInputDevice8W *iface,
IDirectInputDevice2_Poll( iface );
EnterCriticalSection( &impl->crit );
if (impl->status != STATUS_ACQUIRED)
if (impl->status == STATUS_UNPLUGGED)
hr = DIERR_INPUTLOST;
else if (impl->status != STATUS_ACQUIRED)
hr = DIERR_NOTACQUIRED;
else if (!(user_format = impl->user_format))
hr = DIERR_INVALIDPARAM;
......@@ -1605,6 +1607,7 @@ static HRESULT WINAPI dinput_device_GetDeviceData( IDirectInputDevice8W *iface,
if (This->dinput->dwVersion == 0x0800 || size == sizeof(DIDEVICEOBJECTDATA_DX3))
{
if (!This->queue_len) return DIERR_NOTBUFFERED;
if (This->status == STATUS_UNPLUGGED) return DIERR_INPUTLOST;
if (This->status != STATUS_ACQUIRED) return DIERR_NOTACQUIRED;
}
......@@ -1857,7 +1860,8 @@ static HRESULT WINAPI dinput_device_Poll( IDirectInputDevice8W *iface )
HRESULT hr = DI_NOEFFECT;
EnterCriticalSection( &impl->crit );
if (impl->status != STATUS_ACQUIRED) hr = DIERR_NOTACQUIRED;
if (impl->status == STATUS_UNPLUGGED) hr = DIERR_INPUTLOST;
else if (impl->status != STATUS_ACQUIRED) hr = DIERR_NOTACQUIRED;
LeaveCriticalSection( &impl->crit );
if (FAILED(hr)) return hr;
......
......@@ -73,6 +73,7 @@ enum device_status
{
STATUS_UNACQUIRED,
STATUS_ACQUIRED,
STATUS_UNPLUGGED,
};
/* Device implementation */
......
......@@ -1261,7 +1261,6 @@ static DWORD WINAPI dinput_thread_proc( void *params )
struct dinput_device *impl, *next;
SIZE_T events_count = 0;
HANDLE finished_event;
HRESULT hr;
DWORD ret;
MSG msg;
......@@ -1282,8 +1281,11 @@ static DWORD WINAPI dinput_thread_proc( void *params )
{
if (impl->read_event == events[ret])
{
hr = impl->vtbl->read( &impl->IDirectInputDevice8W_iface );
if (FAILED( hr )) dinput_device_internal_unacquire( &impl->IDirectInputDevice8W_iface );
if (FAILED( impl->vtbl->read( &impl->IDirectInputDevice8W_iface ) ))
{
dinput_device_internal_unacquire( &impl->IDirectInputDevice8W_iface );
impl->status = STATUS_UNPLUGGED;
}
break;
}
}
......
......@@ -872,7 +872,7 @@ static HRESULT hid_joystick_acquire( IDirectInputDevice8W *iface )
{
impl->device = CreateFileW( impl->device_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING, 0 );
if (impl->device == INVALID_HANDLE_VALUE) return DIERR_INVALIDPARAM;
if (impl->device == INVALID_HANDLE_VALUE) return DIERR_UNPLUGGED;
}
memset( &impl->read_ovl, 0, sizeof(impl->read_ovl) );
......@@ -882,7 +882,7 @@ static HRESULT hid_joystick_acquire( IDirectInputDevice8W *iface )
{
CloseHandle( impl->device );
impl->device = INVALID_HANDLE_VALUE;
return DIERR_INVALIDPARAM;
return DIERR_UNPLUGGED;
}
IDirectInputDevice8_SendForceFeedbackCommand( iface, DISFFC_RESET );
......
......@@ -116,20 +116,15 @@ static BOOL test_input_lost( DWORD version )
pnp_driver_stop();
hr = IDirectInputDevice8_GetDeviceState( device, sizeof(state), &state );
todo_wine
ok( hr == DIERR_INPUTLOST, "GetDeviceState returned %#x\n", hr );
hr = IDirectInputDevice8_GetDeviceState( device, sizeof(state), &state );
todo_wine
ok( hr == DIERR_INPUTLOST, "GetDeviceState returned %#x\n", hr );
hr = IDirectInputDevice8_GetDeviceData( device, size, objdata, &count, DIGDD_PEEK );
todo_wine
ok( hr == DIERR_INPUTLOST, "GetDeviceData returned %#x\n", hr );
hr = IDirectInputDevice8_Poll( device );
todo_wine
ok( hr == DIERR_INPUTLOST, "Poll returned: %#x\n", hr );
hr = IDirectInputDevice8_Acquire( device );
todo_wine
ok( hr == DIERR_UNPLUGGED, "Acquire returned %#x\n", hr );
hr = IDirectInputDevice8_GetDeviceState( device, sizeof(state), &state );
ok( hr == DIERR_NOTACQUIRED, "GetDeviceState returned %#x\n", hr );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment