dinput: Call device read_callback while holding the internal CS.

And remove the device from the list of acquired devices if the callback
indicates a read error.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-10-08 15:36:02 +02:00 committed by Alexandre Julliard
parent bbb68aeaae
commit c93813e11f
1 changed files with 5 additions and 12 deletions

View File

@ -1289,11 +1289,11 @@ static LRESULT CALLBACK callwndproc_proc( int code, WPARAM wparam, LPARAM lparam
static DWORD WINAPI hook_thread_proc(void *param) static DWORD WINAPI hook_thread_proc(void *param)
{ {
static HHOOK kbd_hook, mouse_hook; static HHOOK kbd_hook, mouse_hook;
IDirectInputDeviceImpl *impl; IDirectInputDeviceImpl *impl, *next;
IDirectInputDevice8W *iface;
SIZE_T events_count = 0; SIZE_T events_count = 0;
HANDLE finished_event; HANDLE finished_event;
HANDLE events[128]; HANDLE events[128];
HRESULT hr;
DWORD ret; DWORD ret;
MSG msg; MSG msg;
@ -1310,24 +1310,17 @@ static DWORD WINAPI hook_thread_proc(void *param)
if (ret < events_count) if (ret < events_count)
{ {
iface = NULL;
EnterCriticalSection( &dinput_hook_crit ); EnterCriticalSection( &dinput_hook_crit );
LIST_FOR_EACH_ENTRY( impl, &acquired_device_list, IDirectInputDeviceImpl, entry ) LIST_FOR_EACH_ENTRY_SAFE( impl, next, &acquired_device_list, IDirectInputDeviceImpl, entry )
{ {
if (impl->read_event == events[ret]) if (impl->read_event == events[ret])
{ {
iface = &impl->IDirectInputDevice8W_iface; hr = impl->read_callback( &impl->IDirectInputDevice8W_iface );
IDirectInputDevice8_AddRef( iface ); if (FAILED(hr)) list_remove( &impl->entry );
break; break;
} }
} }
LeaveCriticalSection( &dinput_hook_crit ); LeaveCriticalSection( &dinput_hook_crit );
if (iface)
{
impl->read_callback( iface );
IDirectInputDevice8_Release( iface );
}
} }
while (PeekMessageW( &msg, 0, 0, 0, PM_REMOVE )) while (PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))