Day 17 : Access violation in Assert

When running my code after completing Day 17, I get an error for an unhandled exception when I press a key on the keyboard. Specifically, it is on the Assert in win32ProcessKeyboardMessage function.

As a check I downloaded and compiled Casey's code for this day and did not have this issue. Looking over both sets of code, I couldn't find the issue with my code as code looked to be identical in the functional areas.

I have no idea what could be causing this error.

Edited by hobbes543 on Reason: Initial post
Nobody will be able to help you with this unless you will show your code... If Casey's code works, but your's doesn't, then there is a bug in your code.
The unhandled exception is the assert. That's because

1
2
// rem:  From Win32ProcessKeyboardMessage in win32_handmade.cpp
    Assert(NewState->EndedDown != IsDown);


Fails.

The first thing I would do is look at how `NewState->EndedDown` is initialized.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
// rem:  Lines 706-721 in win32_handmade.cpp
                    // TODO(casey): Zeroing macro
                    // TODO(casey): We can't zero everything because the up/down state will
                    // be wrong!!!
                    game_controller_input *OldKeyboardController = GetController(OldInput, 0);
                    game_controller_input *NewKeyboardController = GetController(NewInput, 0);
                    *NewKeyboardController = {};
                    NewKeyboardController->IsConnected = true;
                    for(int ButtonIndex = 0;
                        ButtonIndex < ArrayCount(NewKeyboardController->Buttons);
                        ++ButtonIndex)
                    {
                        NewKeyboardController->Buttons[ButtonIndex].EndedDown =
                            OldKeyboardController->Buttons[ButtonIndex].EndedDown;
                    }

                    Win32ProcessPendingMessages(NewKeyboardController);


Make sure that NewKeyboardController is being initialized as expected.