diff --git a/main.py b/main.py index f118ef0..06611e8 100644 --- a/main.py +++ b/main.py @@ -130,6 +130,19 @@ class PedalApp: ) self.audio_system = AudioSystem(self.audio_config) self.audio_system.setup_i2s(reboot_hint=True) + + # Clean stale JACK SHM segments from prior crashes before starting + try: + import shutil + from pathlib import Path + for p in Path("/dev/shm").glob("jack*"): + if p.is_dir(): + shutil.rmtree(p, ignore_errors=True) + else: + p.unlink(missing_ok=True) + except Exception: + pass + if self.audio_config.jack_enabled: self.audio_system.start_jack(timeout=10) else: diff --git a/src/system/audio.py b/src/system/audio.py index 5ed7358..65fe328 100644 --- a/src/system/audio.py +++ b/src/system/audio.py @@ -359,6 +359,18 @@ class AudioSystem: subprocess.run(["killall", "-9", "jackd"], capture_output=True) except FileNotFoundError: pass + # Clean up stale JACK shared memory segments — these prevent a + # new JACK instance from starting if left behind after a crash + # or forceful kill. + try: + import shutil + for p in Path("/dev/shm").glob("jack*"): + if p.is_dir(): + shutil.rmtree(p, ignore_errors=True) + else: + p.unlink(missing_ok=True) + except Exception: + pass def restart_jack(self, timeout: int = 10) -> bool: """Restart JACK server."""