Skip to content

Commit

Permalink
Handle lack of an audio device gracefully without hangs
Browse files Browse the repository at this point in the history
  • Loading branch information
wheremyfoodat committed Dec 4, 2024
1 parent 63cbfbb commit 873fca0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/audio/miniaudio_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ class MiniAudioDevice {

void start();
void stop();

bool isInitialized() const { return initialized; }
};
4 changes: 4 additions & 0 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ RomFS::DumpingResult Emulator::dumpRomFS(const std::filesystem::path& path) {
}

void Emulator::setAudioEnabled(bool enable) {
// Don't enable audio if we didn't manage to find an audio device and initialize it properly, otherwise audio sync will break,
// because the emulator will expect the audio device to drain the sample buffer, but there's no audio device running...
enable = enable && audioDevice.isInitialized();

if (!enable) {
audioDevice.stop();
} else if (enable && romType != ROMType::None && running) {
Expand Down

0 comments on commit 873fca0

Please sign in to comment.