Skip to content

Run without music when no MIDI backend exists - #694

Open
HeikkiSairanen wants to merge 1 commit into
Attnam:masterfrom
HeikkiSairanen:fix/675-run-without-midi
Open

HeikkiSairanen wants to merge 1 commit into
Attnam:masterfrom
HeikkiSairanen:fix/675-run-without-midi

Conversation

@HeikkiSairanen

@HeikkiSairanen HeikkiSairanen commented Nov 6, 2026 •

Copy link
Copy Markdown

Fixes #675.

Related to #637, where the same MIDI Out Error stopped 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 RtMidiOut can't be created, for example when /dev/snd/seq is missing in a container or on a headless machine. audio::Init calls ABORT("MIDI Out Error"), which ends in exit(4).

That exit is also the cause of the Memcheck report in #675. exit() doesn't unwind the stack, so the temporary from audio::Init(game::GetMusicDir()) is never destroyed, and ~MusDir only drops the refcount. festring keeps a pointer 8 bytes into the block, so Memcheck calls it "possibly lost".

Changes

All in audio/audio.cpp:

  • audio::Init returns instead of aborting, leaving midiout null and the audio thread unstarted.
  • GetMIDIOutputDevices returns 0 when midiout is null. It runs during ivanconfig::Initialize (iconf.cpp:1304), so startup would otherwise crash there. The MIDI option then shows "no".
  • ChangeMIDIOutputDevice returns early when midiout is null. It also runs at startup (iconf.cpp:1356), and CurrentMIDIOutPort starts at -1, so even port 0 would reach midiout->isPortOpen().

The remaining midiout uses are only reached from the audio thread, which doesn't run in this case. SetPlaybackStatus won't hang, because isTrackPlaying stays false.

Testing

Builds on macOS arm64 (Release), and audio/audio.cpp compiles 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:

Mode Result
Forced failure, old ABORT restored Quits with MIDI Out Error, exit code 4
Forced failure, with this PR Reaches the main menu
Normal launch Reaches the main menu
Normal launch with a FluidSynth MIDI output Music plays

The 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.

  • Linux, with /dev/snd/seq unavailable: the game reaches the main menu and the 136-byte Memcheck entry is gone.
  • Configuration screen: the MIDI option shows "no" when no device is available.
  • With a working MIDI output: music still plays. Tested on macOS through a FluidSynth CoreMIDI port, with Dungeon.mid copied over mainmenu.mid in a local install because mainmenu.mid has no notes. Not tested with an ALSA sequencer on Linux.

Known limitations

  • A sequencer that appears after launch isn't picked up until the next restart.
  • On a system with no audio at all, sfx.cpp may 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

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
HeikkiSairanen marked this pull request as ready for review November 6, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MEMCHECK: 136 bytes in 1 blocks are possibly lost in loss record

1 participant