___________________________________________________________
PROBLEM:
I'm having this issue with the Keyboard class and I'm not quite sure why. Can somebody explain what is going on?
Basically I have created a Menu class for the Snake Game and I have a function called navigate(). That uses the keyboard input to navigate through the menu.
If I make the navigate function take a Keyboard parameter like this:
Code: Select all
void Menu::navigate(Keyboard &kbd)
{
int option = -1;
while ( !kbd.KeyIsEmpty() ) {
const Keyboard::Event e = kbd.ReadKey();
if (e.IsRelease()) {
if (e.GetCode() == VK_UP || e.GetCode() == VK_DOWN || e.GetCode() == 0x53 || e.GetCode() == 0x57) {
buttonPressed = false;
}
}
...
Menu.h:
Code: Select all
Keyboard &kbd;
It compiles fine but throws an error at runtime: "Couldn't read from memory location 0xFFFFFFFFF (not sure how many F's)
_______________________________________________________________________
SOLUTION:
The issue was that I was not actually sending the Keyboard reference from Game.cpp
So I had to add kbd(kbd) to the constructor's initializing list:
Menu.cpp:
Code: Select all
Menu::Menu(Keyboard &kbd) {
:
kbd(kbd)
}
Code: Select all
Game::Game(MainWindow& wnd)
:
menu(wnd.kbd),