Repository navigation
Run without music when no MIDI backend exists - #694
Open
HeikkiSairanen wants to merge 1 commit into
Open
HeikkiSairanen wants to merge 1 commit into
HeikkiSairanen wants to merge 1 commit into
Conversation
audio::Init called ABORT when RtMidiOut could not be created, for example when /dev/snd/seq is missing in a container or on a headless machine. IVAN therefore refused to start at all. Exiting from inside Init also skipped the destructor of the temporary music directory string, which Memcheck reported as a possibly lost block. Return from Init instead, leaving midiout null and the audio thread unstarted. GetMIDIOutputDevices and ChangeMIDIOutputDevice run during ivanconfig::Initialize, so make both handle a null midiout. No other midiout use is reachable, as they all run on the audio thread. Fixes Attnam#675 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HeikkiSairanen
marked this pull request as ready for review
November 6, 2026 13:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #675.
Related to #637, where the same
MIDI Out Errorstopped IVAN starting on a laptop whose kernel had no sequencer support, until the kernel was rebuilt. This PR doesn't address the build or display problems also reported there.IVAN currently refuses to start when
RtMidiOutcan't be created, for example when/dev/snd/seqis missing in a container or on a headless machine.audio::InitcallsABORT("MIDI Out Error"), which ends inexit(4).That exit is also the cause of the Memcheck report in #675.
exit()doesn't unwind the stack, so the temporary fromaudio::Init(game::GetMusicDir())is never destroyed, and~MusDironly drops the refcount.festringkeeps a pointer 8 bytes into the block, so Memcheck calls it "possibly lost".Changes
All in
audio/audio.cpp:audio::Initreturns instead of aborting, leavingmidioutnull and the audio thread unstarted.GetMIDIOutputDevicesreturns 0 whenmidioutis null. It runs duringivanconfig::Initialize(iconf.cpp:1304), so startup would otherwise crash there. The MIDI option then shows "no".ChangeMIDIOutputDevicereturns early whenmidioutis null. It also runs at startup (iconf.cpp:1356), andCurrentMIDIOutPortstarts at -1, so even port 0 would reachmidiout->isPortOpen().The remaining
midioutuses are only reached from the audio thread, which doesn't run in this case.SetPlaybackStatuswon't hang, becauseisTrackPlayingstays false.Testing
Builds on macOS arm64 (Release), and
audio/audio.cppcompiles with no warnings. It hasn't been built on Linux yet.CoreMIDI doesn't fail on its own, so I ran it on macOS with a local test-only switch, not part of this PR, that throws from the
new RtMidiOut()block:ABORTrestoredMIDI Out Error, exit code 4The main menu was confirmed from a backtrace (
main→iosystem::Menu→ReadKey), not by seeing it on screen.The checks below haven't been done. The Memcheck explanation above comes from reading the code and hasn't been confirmed under Valgrind.
/dev/snd/sequnavailable: the game reaches the main menu and the 136-byte Memcheck entry is gone.Dungeon.midcopied overmainmenu.midin a local install becausemainmenu.midhas no notes. Not tested with an ALSA sequencer on Linux.Known limitations
sfx.cppmay still show its "Unable to initialize audio" alert. That path doesn't quit the game, and this PR doesn't change it.🤖 Generated with Claude Code