From 4a1970dfb5c166527c2049392ea608f77dccd9f8 Mon Sep 17 00:00:00 2001 From: Detanup01 <91248446+Detanup01@users.noreply.github.com> Date: Sun, 20 Jul 2025 13:51:42 +0200 Subject: [PATCH] fix VoiceSystem initialization --- dll/dll/voicechat.h | 2 +- dll/voicechat.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dll/dll/voicechat.h b/dll/dll/voicechat.h index 6efbf7f1..f4a2934f 100644 --- a/dll/dll/voicechat.h +++ b/dll/dll/voicechat.h @@ -82,4 +82,4 @@ public: void QueueIncomingVoice(uint64_t userId, const uint8_t* data, size_t len); }; -#endif // VOICECHAT_INCLUDE_H \ No newline at end of file +#endif // VOICECHAT_INCLUDE_H diff --git a/dll/voicechat.cpp b/dll/voicechat.cpp index f6550902..61a720dc 100644 --- a/dll/voicechat.cpp +++ b/dll/voicechat.cpp @@ -1,12 +1,14 @@ #include "dll/voicechat.h" + +static std::atomic isInited{ false }; bool VoiceChat::InitVoiceSystem() { - static std::atomic initCount{ 0 }; - if (initCount++ == 0) { + if (!isInited) { if (Pa_Initialize() != paNoError) { PRINT_DEBUG("PortAudio initialization failed"); return false; - } + } + isInited = true; } isRecording = false; isPlaying = false; @@ -17,9 +19,9 @@ bool VoiceChat::InitVoiceSystem() { } void VoiceChat::ShutdownVoiceSystem() { - static std::atomic initCount{ 1 }; - if (--initCount == 0) { - Pa_Terminate(); + if (isInited) { + Pa_Terminate(); + isInited = false; } } @@ -250,4 +252,4 @@ void VoiceChat::QueueIncomingVoice(uint64_t userId, const uint8_t* data, size_t if (!data || len == 0) return; std::lock_guard lock(playbackQueueMutex); playbackQueue.push({ userId, std::vector(data, data + len) }); -} \ No newline at end of file +}