1
0
Fork 0
mirror of https://github.com/Detanup01/gbe_fork.git synced 2025-08-08 08:35:40 +02:00

Merge pull request #290 from Detanup01/voicechat-fix

fix VoiceSystem initialization
This commit is contained in:
Detanup01 2025-07-20 20:56:56 +02:00 committed by GitHub
commit 1d2e40f29b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View file

@ -1,12 +1,14 @@
#include "dll/voicechat.h" #include "dll/voicechat.h"
static std::atomic<bool> isInited{ false };
bool VoiceChat::InitVoiceSystem() { bool VoiceChat::InitVoiceSystem() {
static std::atomic<int> initCount{ 0 }; if (!isInited) {
if (initCount++ == 0) {
if (Pa_Initialize() != paNoError) { if (Pa_Initialize() != paNoError) {
PRINT_DEBUG("PortAudio initialization failed"); PRINT_DEBUG("PortAudio initialization failed");
return false; return false;
} }
isInited = true;
} }
isRecording = false; isRecording = false;
isPlaying = false; isPlaying = false;
@ -17,9 +19,9 @@ bool VoiceChat::InitVoiceSystem() {
} }
void VoiceChat::ShutdownVoiceSystem() { void VoiceChat::ShutdownVoiceSystem() {
static std::atomic<int> initCount{ 1 }; if (isInited) {
if (--initCount == 0) {
Pa_Terminate(); Pa_Terminate();
isInited = false;
} }
} }