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 +}