Signed-off-by: Arkadiusz Hiler ahiler@codeweavers.com --- dlls/dinput/device.c | 18 ++++++++++++------ dlls/dinput8/tests/device.c | 12 ++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 198e903fc2e..14c47dd3c7d 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -833,6 +833,7 @@ HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, L DWORD username_size = MAX_PATH; int i, action = 0, num_actions = 0; unsigned int offset = 0; + ActionMap *action_map;
if (This->acquired) return DIERR_ACQUIRED;
@@ -848,15 +849,12 @@ HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, L
if (num_actions == 0) return DI_NOEFFECT;
- This->num_actions = num_actions; - /* Construct the dataformat and actionmap */ obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions); data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df; data_format.dwNumObjs = num_actions;
- HeapFree(GetProcessHeap(), 0, This->action_map); - This->action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions); + action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
for (i = 0; i < lpdiaf->dwNumActions; i++) { @@ -873,8 +871,8 @@ HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, L
memcpy(&obj_df[action], obj, df->dwObjSize);
- This->action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData; - This->action_map[action].offset = offset; + action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData; + action_map[action].offset = offset; obj_df[action].dwOfs = offset; offset += (type & DIDFT_BUTTON) ? 1 : 4;
@@ -884,6 +882,9 @@ HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, L
IDirectInputDevice8_SetDataFormat(iface, &data_format);
+ This->action_map = action_map; + This->num_actions = num_actions; + HeapFree(GetProcessHeap(), 0, obj_df);
/* Set the device properties according to the action format */ @@ -962,6 +963,7 @@ void queue_event(LPDIRECTINPUTDEVICE8A iface, int inst_id, DWORD data, DWORD tim This->data_queue[This->queue_head].dwData = data; This->data_queue[This->queue_head].dwTimeStamp = time; This->data_queue[This->queue_head].dwSequence = seq; + This->data_queue[This->queue_head].uAppData = -1;
/* Set uAppData by means of action mapping */ if (This->num_actions > 0) @@ -1063,6 +1065,10 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetDataFormat(LPDIRECTINPUTDEVICE8W ifac
EnterCriticalSection(&This->crit);
+ HeapFree(GetProcessHeap(), 0, This->action_map); + This->action_map = NULL; + This->num_actions = 0; + release_DataFormat(&This->data_format); res = create_DataFormat(df, &This->data_format);
diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c index 02574961ec1..4a766280982 100644 --- a/dlls/dinput8/tests/device.c +++ b/dlls/dinput8/tests/device.c @@ -362,6 +362,18 @@ static void test_action_mapping(void) /* Test keyboard input */ test_device_input(data.keyboard, INPUT_KEYBOARD, VK_SPACE, 2);
+ /* setting format should reset action map */ + hr = IDirectInputDevice8_SetDataFormat(data.keyboard, &c_dfDIKeyboard); + ok (SUCCEEDED(hr), "IDirectInputDevice8_SetDataFormat failed: %08x\n", hr); + + test_device_input(data.keyboard, INPUT_KEYBOARD, VK_SPACE, -1); + + /* back to action map */ + hr = IDirectInputDevice8_SetActionMap(data.keyboard, data.lpdiaf, NULL, 0); + ok (SUCCEEDED(hr), "SetActionMap should succeed hr=%08x\n", hr); + + test_device_input(data.keyboard, INPUT_KEYBOARD, VK_SPACE, 2); + /* Test BuildActionMap with no suitable actions for a device */ IDirectInputDevice_Unacquire(data.keyboard); af.dwDataSize = 4 * DITEST_KEYBOARDSPACE;