From a78f65b274448526a84bbd02067c9c8501a21984 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Tue, 17 Nov 2020 23:10:19 +0100 Subject: [PATCH] fix getch spin --- src/Console.cpp | 12 ++++++++++-- src/logger.cpp | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Console.cpp b/src/Console.cpp index e399331..b7e1a4b 100644 --- a/src/Console.cpp +++ b/src/Console.cpp @@ -174,11 +174,19 @@ static void ProcessCompositeInput() { } } -[[noreturn]] void ReadCin() { +void ReadCin() { DebugPrintTID(); + size_t null_byte_counter = 0; while (true) { int In = _getch(); - // info(std::to_string(In)); + info(std::to_string(In)); + if (In == 0) { + ++null_byte_counter; + if (null_byte_counter > 0) { + info("too many null bytes in input, this is now assumed to be a background thread - console input is now disabled"); + break; + } + } if (CompositeInputExpected) { CompositeInput += char(In); #ifdef WIN32 diff --git a/src/logger.cpp b/src/logger.cpp index 99e231b..73e7bb9 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include static RWMutex ThreadNameMapMutex; @@ -94,7 +95,7 @@ void DebugPrintTIDInternal(const std::string& func, bool overwrite) { #ifdef DEBUG std::scoped_lock Guard(LogLock); std::stringstream Print; - Print << "(debug build) Thread '" << std::this_thread::get_id() << "' is " << func << "\n"; + Print << "(debug build) Thread '" << std::this_thread::get_id() << "' / '" << gettid() << "' is " << func << "\n"; ConsoleOut(Print.str()); #endif // DEBUG }