From e4613a34870785139ba6ff78c7123a1605f1ab5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 20 Aug 2026 00:35:30 +0200 Subject: [PATCH] WaveFile: don't assert-crash when the wav file couldn't be opened __StartLogAudio ignored WaveFileWriter::Start()'s return value and set m_logAudio either way, so a wav file that couldn't be opened - read-only or full audio directory, most likely - left every subsequent mixed block calling AddStereoSamples on a closed file. That opens with _assert_msg_(file, ...). Also other minor fixes. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9 --- Core/HLE/__sceAudio.cpp | 9 ++++++++- Core/WaveFile.cpp | 11 +++++++---- Core/WaveFile.h | 2 -- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Core/HLE/__sceAudio.cpp b/Core/HLE/__sceAudio.cpp index a6fe3b22e8..4d433d3b45 100644 --- a/Core/HLE/__sceAudio.cpp +++ b/Core/HLE/__sceAudio.cpp @@ -477,8 +477,15 @@ void __AudioUpdate(bool resetRecording) { #ifndef MOBILE_DEVICE void __StartLogAudio(const Path& filename) { if (!m_logAudio) { + if (!g_wave_writer.Start(filename, 44100)) { + // Start() logs the reason. Leave m_logAudio false, or every mixed block from here on + // would hand samples to a closed file - and turn the setting off too, since otherwise + // the caller below retries this (creating the file, opening it) once per block. + ERROR_LOG(Log::sceAudio, "Failed to start audio logging, disabling it"); + g_Config.bDumpAudio = false; + return; + } m_logAudio = true; - g_wave_writer.Start(filename, 44100); g_wave_writer.SetSkipSilence(false); NOTICE_LOG(Log::sceAudio, "Starting Audio logging"); } else { diff --git a/Core/WaveFile.cpp b/Core/WaveFile.cpp index 44ce0fa421..d78497be5e 100644 --- a/Core/WaveFile.cpp +++ b/Core/WaveFile.cpp @@ -6,8 +6,6 @@ #include "Common/Log.h" #include "Core/Config.h" -constexpr size_t WaveFileWriter::BUFFER_SIZE; - WaveFileWriter::WaveFileWriter() {} WaveFileWriter::~WaveFileWriter() @@ -78,10 +76,15 @@ void WaveFileWriter::Write4(const char* ptr) file.WriteBytes(ptr, 4); } +// count is the number of stereo frames, so 4 bytes each. void WaveFileWriter::AddStereoSamples(const short* sample_data, uint32_t count) { - _assert_msg_(file, "WaveFileWriter - file not open."); - _assert_msg_(count <= BUFFER_SIZE * 2, "WaveFileWriter - buffer too small (count = %u).", count); + if (!file) { + // Callers are supposed to check that Start() succeeded, but this used to assert - which + // isn't compiled out in release builds, so a file we couldn't open crashed the emulator. + ERROR_LOG(Log::System, "WaveFileWriter - file not open."); + return; + } if (skip_silence) { diff --git a/Core/WaveFile.h b/Core/WaveFile.h index 50be39dcb0..fafeebeca4 100644 --- a/Core/WaveFile.h +++ b/Core/WaveFile.h @@ -30,8 +30,6 @@ public: void AddStereoSamples(const short* sample_data, uint32_t count); uint32_t GetAudioSize() const { return audio_size; } private: - static constexpr size_t BUFFER_SIZE = 32 * 1024; - File::IOFile file; bool skip_silence = false; uint32_t audio_size = 0;