Basically, I get a buffer overrun error when using raw input with win32.
I have a RAWINPUTDEVICE variable and register it at startup,
| RAWINPUTDEVICE riMouse;
riMouse.usUsagePage = HID_USAGE_PAGE_GENERIC;
riMouse.usUsage = HID_USAGE_GENERIC_MOUSE;
riMouse.dwFlags = RIDEV_INPUTSINK;
riMouse.hwndTarget = window;
RegisterRawInputDevices(&riMouse, 1, sizeof(riMouse));
|
And then in my PeekMessage() loop I respond to the WM_INPUT call
1
2
3
4
5
6
7
8
9
10
11
12
13 | case WM_INPUT:
{
if(message.wParam == RIM_INPUT && useRelativeMouse)
{
GetRawInputData((HRAWINPUT)message.lParam, RID_INPUT, rawInputData, &dwSize, sizeof(RAWINPUTHEADER));
rawInput = (RAWINPUT*)rawInputData;
if(rawInput->header.dwType == RIM_TYPEMOUSE)
{
input.mouseInput.deltaX = rawInput->data.mouse.lLastX;
input.mouseInput.deltaY = rawInput->data.mouse.lLastY;
}
}
}break;
|
This works for getting the input, however when I exit the program I get
"Stack cookie instrumentation code detected a stack-based buffer overrun."
If I do not call RegisterRawInputDevices() I do not get a crash but obviously the input does not work. I also do not get a crash if I do not move the mouse while running the program.
I tried setting the RIDEV_REMOVE flag on my RAWINPUTDEVICE and calling RegisterRawInputDevices() again, and again this works if I do not move the mouse at all while running.
| riMouse.dwFlags = RIDEV_REMOVE;
riMouse.hwndTarget = 0;
RegisterRawInputDevices(&riMouse, 1, sizeof(riMouse));
riMouse.hwndTarget = window;
RegisterRawInputDevices(&riMouse, 1, sizeof(riMouse));
|
I tried the above with and without the second call of RegisterRawInputDevices() and got the same result with each.
I have read through several examples and I can't find what I am doing wrong.
Thanks for the help.
EDIT *SOLVED*
My rawInputData array was too small I guess, increasing the size worked.