Audio: Properly close audio device on emulator destruction (#637)

* Audio: Properly close audio device on emulator destruction

* Undo oopsie
This commit is contained in:
wheremyfoodat 2024-11-19 23:41:52 +02:00 committed by GitHub
parent 452510b932
commit 889c2453de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 7 deletions

View file

@ -21,10 +21,12 @@ class MiniAudioDevice {
bool running = false; bool running = false;
std::vector<std::string> audioDevices; std::vector<std::string> audioDevices;
public: public:
MiniAudioDevice(); MiniAudioDevice();
// If safe is on, we create a null audio device // If safe is on, we create a null audio device
void init(Samples& samples, bool safe = false); void init(Samples& samples, bool safe = false);
void close();
void start(); void start();
void stop(); void stop();

View file

@ -130,7 +130,7 @@ void MiniAudioDevice::start() {
void MiniAudioDevice::stop() { void MiniAudioDevice::stop() {
if (!initialized) { if (!initialized) {
Helpers::warn("MiniAudio device not initialized, can't start"); Helpers::warn("MiniAudio device not initialized, can't stop");
return; return;
} }
@ -142,3 +142,14 @@ void MiniAudioDevice::stop() {
} }
} }
} }
void MiniAudioDevice::close() {
stop();
if (initialized) {
initialized = false;
ma_device_uninit(&device);
ma_context_uninit(&context);
}
}

View file

@ -50,6 +50,7 @@ Emulator::Emulator()
Emulator::~Emulator() { Emulator::~Emulator() {
config.save(); config.save();
lua.close(); lua.close();
audioDevice.close();
#ifdef PANDA3DS_ENABLE_DISCORD_RPC #ifdef PANDA3DS_ENABLE_DISCORD_RPC
discordRpc.stop(); discordRpc.stop();