virtual function called error fix

This commit is contained in:
folkert van heusden 2022-03-22 22:18:06 +01:00
parent 899af8e5d5
commit d8d1fdc92c
7 changed files with 29 additions and 13 deletions

View file

@ -27,8 +27,8 @@ add_executable(
include(CheckIPOSupported)
check_ipo_supported(RESULT supported)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
#set(CMAKE_BUILD_TYPE Debug)
#set(CMAKE_BUILD_TYPE RelWithDebInfo)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)

View file

@ -8,10 +8,16 @@
console_esp32::console_esp32(std::atomic_bool *const terminate) : console(terminate)
{
th = new std::thread(std::ref(*this));
}
console_esp32::~console_esp32()
{
if (th) {
th->join();
delete th;
}
}
int console_esp32::wait_for_char(const int timeout)

View file

@ -12,17 +12,10 @@ console::console(std::atomic_bool *const terminate) :
terminate(terminate)
{
memset(screen_buffer, ' ', sizeof screen_buffer);
th = new std::thread(std::ref(*this));
}
console::~console()
{
if (th) {
th->join();
delete th;
}
}
bool console::poll_char()

View file

@ -13,8 +13,6 @@ class console
private:
std::atomic_bool *const terminate { nullptr };
std::thread *th { nullptr };
std::vector<char> input_buffer;
char screen_buffer[t_height][t_width];
@ -22,6 +20,8 @@ private:
uint8_t ty { 0 };
protected:
std::thread *th { nullptr };
virtual int wait_for_char(const int timeout) = 0;
virtual void put_char_ll(const char c) = 0;

View file

@ -12,10 +12,18 @@ console_ncurses::console_ncurses(std::atomic_bool *const terminate) : console(te
init_ncurses(true);
resize_terminal();
th = new std::thread(std::ref(*this));
}
console_ncurses::~console_ncurses()
{
if (th) {
th->join();
delete th;
}
wprintw(w_main->win, "\n\n *** PRESS ENTER TO TERMINATE ***\n");
mydoupdate();

View file

@ -17,12 +17,21 @@ console_posix::console_posix(std::atomic_bool *const terminate) : console(termin
if (tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw) == -1)
error_exit(true, "console_posix: tcsetattr failed");
th = new std::thread(std::ref(*this));
}
console_posix::~console_posix()
{
if (th) {
th->join();
delete th;
}
if (tcsetattr(STDIN_FILENO, TCSANOW, &org_tty_opts) == -1)
error_exit(true, "~console_posix: tcsetattr failed");
}
int console_posix::wait_for_char(const int timeout)

View file

@ -306,11 +306,11 @@ int main(int argc, char *argv[])
terminate = true;
delete b;
delete cnsl;
fprintf(stderr, "Instructions per second: %.3f\n\n", icount * 1000.0 / (get_ms() - start));
delete b;
return 0;
}