https://hero.handmade.network/for...scussion/t/873-day_017_dinput_woe
My assert is going off on Win32ProcessKeyboardMessage. Casey's code runs fine, mine will run fine only with the debugger when stepping through, any normal run without stepping through throws the exception from the ASSERT macro. Code:
Win32ProcessKeyboardMessage():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | // ... case WM_SYSKEYDOWN: case WM_SYSKEYUP: case WM_KEYDOWN: case WM_KEYUP: { // 24th bit is extended keys, numpad, right alt & ctrl // 29th bit is context code - alt key down // 30th bit is Previous key state - reapeated keydown is 1 // 31st bit is Transistion state - 0 for down uint32 VKCode = (uint32)Message.wParam; bool32 WasDown = ((Message.lParam & (1 << 30)) != 0); bool32 IsDown = ((Message.lParam & (1 << 31)) == 0); // Ignore duplicate input if (WasDown != IsDown) { //Win32AssignKeyboard(keyboard, VKCode, IsDown); if (VKCode == 'W') { Win32ProcessKeyboardMessage(&keyboard->MoveUp, IsDown); OutputDebugStringA("KEYDOWN\n"); } else if (VKCode == 'A') { Win32ProcessKeyboardMessage(&keyboard->MoveLeft, IsDown); } else if (VKCode == 'S') { Win32ProcessKeyboardMessage(&keyboard->MoveDown, IsDown); } else if (VKCode == 'D') { Win32ProcessKeyboardMessage(&keyboard->MoveRight, IsDown); } } // ... |
WinMain():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | // ... game_input Input[2] = {}; game_input *NewInput = &Input[0]; game_input *OldInput = &Input[1]; // ... while (Running) { // I've copied Caseys code here and it produces the same error with Old/NewKeyboardController game_controller *Keyboard = &NewInput->Controllers[0]; *Keyboard = {}; Keyboard->IsConnected = true; for (int KeyIndex = 0; KeyIndex < ArrayCount(Keyboard->Buttons); ++KeyIndex) { Keyboard->Buttons[KeyIndex].IsDown = OldInput->Controllers[0].Buttons[KeyIndex].IsDown; } Win32ProcessPendingMessages(Keyboard); // ... game_input *Temp = NewInput; NewInput = OldInput; OldInput = Temp; } |
Any ideas would be greatly appreciated!