Ok, above theory
may be the cause, but it's a stab in the dark entirely, as I don't get said error on my xbox.
To test, you need to check for corruption of memory around the g_InputStatesEx structure. So what I suggest you do is create a temporary backup of g_InputStatesEx before the XGetInputState() call, then do the call. Then compare to your backup outside of the particular state you're reading.
i.e.
Code:
memcpy(backup, g_InputStatesEx, sizeof(backup));
ZeroMemory( &g_InputStatesEx[i], sizeof(XINPUT_STATEEX) );
if (ERROR_SUCCESS == XInputGetState( g_IR_Remote[i].hDevice, (XINPUT_STATE*) &g_InputStatesEx[i] ))
{
// compare from backup to g_InputStatesEx;
for (int j = 0; j < 4; j++)
{
if (j != i && memcmp(&backup[j], &g_InputStatesEx[j], sizeof(XINPUT_STATEEX)) != 0)
CLog::Log(LOGFATAL, "Holy shit, batman, we're as corrupt as the Penguin!");
}
If that is indeed the fault, you
should get output from it before you get hit with an exception.
The fix is to extend XINPUT_STATE_EX as follows:
Code:
typedef struct _XINPUT_STATEEX
{
#pragma pack( push, before_header )
#pragma pack(1)
DWORD dwPacketNumber;
union // added by JM to attempt to fix the memory corruption issues - XGetInputState() writes to an
// XINPUT_STATE pointer, so we pad this structure out so that it's at least sizeof(XINPUT_STATE)
{
XINPUT_GAMEPAD Gamepad;
XINPUT_IR_REMOTE IR_Remote;
};
#pragma pack( pop, before_header )
}
XINPUT_STATEEX, *PXINPUT_STATEEX;
Cheers,
Jonathan