Files
m2dev-client-src/src/AudioLib/MaSoundInstance.h
nbsnl 6227fed5be Fix fullscreen startup crash caused by WASAPI audio initialization
The client was crashing during fullscreen initialization due to a NULL 
IMMDeviceEnumerator pointer inside miniaudio’s WASAPI backend.

Crash location:
ma_IMMDeviceEnumerator_GetDefaultAudioEndpoint
(inlined in ma_device_init_internal__wasapi)

Disassembly showed a null vtable dereference:
call qword ptr [rax+20h]

On some systems, WASAPI fails to create or retrieve the default audio endpoint
(especially in VMs, RDP sessions, missing/disabled audio devices, or timing
issues during fullscreen initialization). This results in a NULL COM pointer 
being used, causing a 0xC0000005 access violation before the game window fully 
appears.

Solution:
WASAPI backend has been disabled and the client now falls back to the more stable 
DirectSound/WinMM audio backends.

Applied definitions:
#define MA_NO_WASAPI
#define MA_ENABLE_DSOUND
#define MA_ENABLE_WINMM

Results:
✔ Fullscreen crash completely resolved
✔ Audio still works through DirectSound
✔ Improved stability across fullscreen/windowed modes
✔ No functional drawbacks observed
2025-11-15 23:48:28 +03:00

58 lines
1.0 KiB
C++

#pragma once
#define MA_NO_WASAPI
#define MA_ENABLE_DSOUND
#define MA_ENABLE_WINMM
#include <miniaudio.h>
inline constexpr float CS_CLIENT_FPS = 61.0f;
class MaSoundInstance
{
public:
bool InitFromBuffer(ma_engine& engine, const std::vector<uint8_t>& buffer, const std::string& identity);
bool InitFromFile(ma_engine& engine, const std::string& filePathOnDisk);
void Destroy();
bool IsInitialized() const;
bool IsPlaying() const;
bool Play();
bool Resume();
bool Stop();
void Loop();
float GetVolume() const;
void SetVolume(float volume);
void SetPitch(float pitch);
void SetPosition(float x, float y, float z);
const std::string& GetIdentity() const;
void Config3D(bool toggle, float minDist = 100.0f/*1m*/, float maxDist = 4000.0f/*40m*/);
void Fade(float toVolume, float secDurationFromMinMax);
void StopFading();
bool IsFading() const;
void Update();
private:
std::string m_Identity;
ma_sound m_Sound{};
ma_decoder m_Decoder{};
bool m_Initialized{};
float m_FadeTargetVolume{};
float m_FadeRatePerFrame{};
};