diff --git a/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp b/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp index 8f633611..aac53d0f 100644 --- a/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp +++ b/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp @@ -862,7 +862,15 @@ void LatteShaderCache_StreamBootSound() while(audiothread_keeprunning) { while (bootSndAudioDev->NeedAdditionalBlocks()) - bootSndAudioDev->FeedBlock(bootSndFileReader->getSamples()); + { + sint16* data = bootSndFileReader->getSamples(); + if(data == nullptr) + { + audiothread_keeprunning = false; + break; + } + bootSndAudioDev->FeedBlock(data); + } // sleep for the duration of a single block std::this_thread::sleep_for(std::chrono::milliseconds(samplesPerBlock / (sampleRate/ 1'000))); } diff --git a/src/util/bootSound/BootSoundReader.cpp b/src/util/bootSound/BootSoundReader.cpp index 52b26e2c..1c969009 100644 --- a/src/util/bootSound/BootSoundReader.cpp +++ b/src/util/bootSound/BootSoundReader.cpp @@ -3,13 +3,15 @@ BootSoundReader::BootSoundReader(FSCVirtualFile* bootsndFile, sint32 blockSize) : bootsndFile(bootsndFile), blockSize(blockSize) { + // crash if this constructor is invoked with a blockSize that has a different number of samples per channel + cemu_assert(blockSize % (sizeof(sint16be) * 2) == 0); + fsc_setFileSeek(bootsndFile, 0); fsc_readFile(bootsndFile, &muteBits, 4); fsc_readFile(bootsndFile, &loopPoint, 4); + buffer.resize(blockSize / sizeof(sint16)); bufferBE.resize(blockSize / sizeof(sint16be)); - if(blockSize % (sizeof(sint16be) * 2) != 0) - cemu_assert_suspicious(); // workaround: SM3DW has incorrect loop point const auto titleId = CafeSystem::GetForegroundTitleId(); @@ -23,8 +25,16 @@ sint16* BootSoundReader::getSamples() while(totalRead < blockSize) { auto read = fsc_readFile(bootsndFile, bufferBE.data(), blockSize - totalRead); + if (read == 0) + { + cemuLog_log(LogType::Force, "failed to read PCM samples from bootSound.btsnd"); + return nullptr; + } if (read % (sizeof(sint16be) * 2) != 0) - cemu_assert_suspicious(); + { + cemuLog_log(LogType::Force, "failed to play bootSound.btsnd: reading PCM data stopped at an odd number of samples (is the file corrupt?)"); + return nullptr; + } std::copy_n(bufferBE.begin(), read / sizeof(sint16be), buffer.begin() + (totalRead / sizeof(sint16))); totalRead += read;