From 9456526896043d0981177074db1587780c0c49fc Mon Sep 17 00:00:00 2001 From: The Zilchotron6000 Date: Tue, 17 Feb 2026 19:05:43 +0000 Subject: [PATCH 1/2] Fix fatal crash on Windows when window title matches MIDI device name On certain Windows systems, pygame.display.set_caption('midimech') causes a fatal native process termination (exit code -1, no traceback) when a MIDI loopback device named 'midimech' is present. This appears to be a case-insensitive collision between SDL's window title and the Windows MIDI subsystem, causing TerminateProcess ~1-2s after the window is created. Fix: Change TITLE from 'midimech' to 'midimech app' to avoid the name collision. Also harden the MIDI callback and shutdown cleanup. --- midimech.py | 20 +++++++++++++++----- src/constants.py | 6 +++++- src/core.py | 9 +++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/midimech.py b/midimech.py index 2db8b2d..c2d366c 100755 --- a/midimech.py +++ b/midimech.py @@ -52,13 +52,23 @@ def main(): try: core = Core() core() - except SystemExit: - pass + except SystemExit as e: + if e.code != 0: + print(f"midimech exited with code {e.code}") except: print(traceback.format_exc()) - del core - pygame.midi.quit() - pygame.display.quit() + try: + del core + except: + pass + try: + pygame.midi.quit() + except: + pass + try: + pygame.display.quit() + except: + pass os._exit(0) # pygame.quit() diff --git a/src/constants.py b/src/constants.py index a8c4b66..b01c03a 100644 --- a/src/constants.py +++ b/src/constants.py @@ -1,6 +1,10 @@ from glm import ivec2, vec2, ivec3, vec3 -TITLE = "midimech" +# CRITICAL: Window title must NOT exactly match the "midimech" MIDI loopback +# device name. On Windows, SDL + the MIDI subsystem causes a fatal native +# process termination when the window title matches a MIDI device name +# (case-insensitive substring match). Adding any differentiating text avoids it. +TITLE = "midimech app" # FOCUS = False NOTES = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"] WHOLETONE = True diff --git a/src/core.py b/src/core.py index 930d754..c61fd5e 100644 --- a/src/core.py +++ b/src/core.py @@ -924,6 +924,15 @@ def note_off(self, data, timestamp, width=None, mpe=None, octave=0, transpose=0, def cb_midi_in(self, data, timestamp, force_channel=None): """LinnStrument MIDI Callback""" + if not hasattr(self, 'board'): + return # not fully initialized yet + try: + self._cb_midi_in(data, timestamp, force_channel) + except Exception as e: + print(f"MIDI callback error: {e}") + + def _cb_midi_in(self, data, timestamp, force_channel=None): + """LinnStrument MIDI Callback (inner)""" # d4 = None # if len(data)==4: # d4 = data[3] From 29abad1e74fd0458993a76953ba38960499d5456 Mon Sep 17 00:00:00 2001 From: The Zilchotron6000 Date: Tue, 17 Feb 2026 19:09:02 +0000 Subject: [PATCH 2/2] =?UTF-8?q?Soften=20comment=20=E2=80=94=20crash=20only?= =?UTF-8?q?=20affects=20some=20Windows=20setups,=20exact=20cause=20unknown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/constants.py b/src/constants.py index b01c03a..abf6ecd 100644 --- a/src/constants.py +++ b/src/constants.py @@ -1,9 +1,8 @@ from glm import ivec2, vec2, ivec3, vec3 -# CRITICAL: Window title must NOT exactly match the "midimech" MIDI loopback -# device name. On Windows, SDL + the MIDI subsystem causes a fatal native -# process termination when the window title matches a MIDI device name -# (case-insensitive substring match). Adding any differentiating text avoids it. +# Window title must not exactly match the "midimech" MIDI loopback device name. +# On some Windows setups, SDL fatally terminates the process when the window +# title matches a MIDI device name (case-insensitive). Exact cause unknown. TITLE = "midimech app" # FOCUS = False NOTES = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]