Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent app crash when miniaudio samples bigger than capacity #596

Merged
merged 2 commits into from
Sep 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core/audio/miniaudio_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,17 @@ void MiniAudioDevice::init(Samples& samples, bool safe) {
deviceConfig.dataCallback = [](ma_device* device, void* out, const void* input, ma_uint32 frameCount) {
auto self = reinterpret_cast<MiniAudioDevice*>(device->pUserData);
s16* output = reinterpret_cast<ma_int16*>(out);
const usize maxSamples = std::min(self->samples->Capacity(), usize(frameCount * channelCount));

// Wait until there's enough samples to pop
while (self->samples->size() < frameCount * channelCount) {
while (self->samples->size() < maxSamples) {
// If audio output is disabled from the emulator thread, make sure that this callback will return and not hang
if (!self->running) {
return;
}
}

self->samples->pop(output, frameCount * channelCount);
self->samples->pop(output, maxSamples);
};

if (ma_device_init(&context, &deviceConfig, &device) != MA_SUCCESS) {
Expand Down
Loading