From 6e9aaa9751c7ecead88ca75b6d8044b55ce2cff7 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Fri, 17 Jan 2025 13:39:29 -0500 Subject: [PATCH] This attempts to fix the error: "Error processing game output: 'gbk' codec can't decode byte 0xac in position 33: illegal multibyte sequence" as reported by nicotomia from the audiogames.net forum. --- Toby Doom Launcher.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Toby Doom Launcher.py b/Toby Doom Launcher.py index 1e28b35..d3fc3da 100755 --- a/Toby Doom Launcher.py +++ b/Toby Doom Launcher.py @@ -225,12 +225,26 @@ class SpeechHandler: while True: try: - line = process.stdout.readline() - # Keep gzdoom's existing functionality of lines being printed to the console. - print(line, end='') - if not line: + # Read raw bytes from stdout + rawLine = process.stdout.buffer.readline() + if not rawLine: break + # Try different encodings + for encoding in ['utf-8', 'latin1', 'cp1252']: + try: + line = rawLine.decode(encoding) + break + except UnicodeDecodeError: + continue + else: + # If all encodings fail, skip this line + print(f"Warning: Could not decode line: {rawLine}", file=sys.stderr) + continue + + # Keep gzdoom's existing functionality of lines being printed to the console + print(line, end='') + lineStr = line.strip() # Wait for the initial separator before starting speech @@ -245,7 +259,7 @@ class SpeechHandler: except Exception as e: print(f"Error processing game output: {e}", file=sys.stderr) - break + continue # Continue processing instead of breaking class MenuDialog(QDialog): @@ -1675,7 +1689,6 @@ class DoomLauncher(QMainWindow): stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, - text=True, env=dict(os.environ, PYTHONUNBUFFERED="1"), startupinfo=startupinfo )