Hey there, im making my first c++ based fullstack app and I have a problem where I need to wait for the player to hit enter asynchronously
The way I have it set up is in two classes: The app class that gets initialized in main and the Input class which gets initialized theoretically whenever I need it. After the init app function I have a cout in main that states that Im back in the main.cpp but it never gets called
But for testing purposes ive made a testinit() and testcallback() within my app class to test functionality and it looks something like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void TestInit()
{
Input* input = new Input();
input->InitInput(this, &App::TestCallback)
do
{
}while(!ejected); // this would be the main program loop, but for now i need
to verify that the input system works
cout << "Out of loop!"
}
void TestCallback()
{
cout << "callback worked UwU";
callbackbool = true; //global bool
}
and in the input class it kind of looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
void InitInput(App* app, void(App::*Callback)())
{
ejected = false; //class bool thats used for detecting if player pressed enter
if(app)
{
application = app;
CallbackFunc = Callback; //class varriables self explainitory
}
std::thread t6(&Input::TakeInput, this);
}
void TakeInput()
{
char keyPressed;
do
{
if (_kbhit())
{
keyPressed = _getch();
if(keyPressed == '\r')// yes its a terminal program leave me alone
{
ejected = true;
(Application->*CallbackFunc)();
}
}
}while(!ejected);
}
And all of this works just fine. I get the output of the call back and all is good in the world but it throws me an error right at the end of the Init function for the app and I dont have the slightest clue as to why. Any help appriciated.
The error it gives me is something along the lines of ESP not properly copied or something