Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Core/GameEngineDevice/Source/MiniAudioDevice/MiniAudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ void MiniAudioManager::update()
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::stopAudio(AudioAffect which)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
if (BitIsSet(which, AudioAffect_Sound))
ma_sound_group_stop(&m_soundGroup);
if (BitIsSet(which, AudioAffect_Sound3D))
Expand All @@ -233,6 +235,8 @@ void MiniAudioManager::stopAudio(AudioAffect which)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::pauseAudio(AudioAffect which)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
if (BitIsSet(which, AudioAffect_Sound))
ma_sound_group_stop(&m_soundGroup);
if (BitIsSet(which, AudioAffect_Sound3D))
Expand All @@ -246,6 +250,8 @@ void MiniAudioManager::pauseAudio(AudioAffect which)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::resumeAudio(AudioAffect which)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
if (BitIsSet(which, AudioAffect_Sound))
ma_sound_group_start(&m_soundGroup);
if (BitIsSet(which, AudioAffect_Sound3D))
Expand Down Expand Up @@ -486,6 +492,8 @@ void MiniAudioManager::playAudioEvent(AudioEventRTS *event)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::stopAudioEvent(AudioHandle handle)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
std::list<PlayingAudio *>::iterator it;

// Handle special music stop commands
Expand Down Expand Up @@ -521,6 +529,8 @@ void MiniAudioManager::stopAudioEvent(AudioHandle handle)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::killAudioEventImmediately(AudioHandle audioEvent)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
// First look for it in the request list.
std::list<AudioRequest *>::iterator ait;
for (ait = m_audioRequests.begin(); ait != m_audioRequests.end(); ait++)
Expand Down Expand Up @@ -551,6 +561,8 @@ void MiniAudioManager::killAudioEventImmediately(AudioHandle audioEvent)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::pauseAudioEvent(AudioHandle handle)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
// TODO: implement individual sound pause
}

Expand Down Expand Up @@ -607,6 +619,8 @@ void MiniAudioManager::releasePlayingAudio(PlayingAudio *release)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::stopAllAudioImmediately(void)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
std::list<PlayingAudio *>::iterator it;
PlayingAudio *playing;

Expand All @@ -632,6 +646,8 @@ void MiniAudioManager::stopAllAudioImmediately(void)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::freeAllMiniAudioHandles(void)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
ma_engine_stop(&m_engine);
}

Expand Down Expand Up @@ -659,6 +675,8 @@ void MiniAudioManager::adjustPlayingVolume(PlayingAudio *audio)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::stopAllSpeech(void)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
std::list<PlayingAudio *>::iterator it;
for (it = m_playingSounds.begin(); it != m_playingSounds.end(); ) {
PlayingAudio *playing = (*it);
Expand Down Expand Up @@ -825,6 +843,8 @@ void MiniAudioManager::openDevice(void)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::closeDevice(void)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
// Stop all audio first to prevent use-after-free in audio callbacks
stopAllAudioImmediately();

Expand Down Expand Up @@ -857,6 +877,8 @@ Bool MiniAudioManager::isCurrentlyPlaying(AudioHandle handle)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::notifyOfAudioCompletion(UnsignedInt audioCompleted, UnsignedInt flags)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
PlayingAudio *playing = findPlayingAudioFrom(audioCompleted, flags);
if (!playing) return;
if (!playing->m_audioEventRTS || !playing->m_audioEventRTS->getAudioEventInfo()) return;
Expand Down Expand Up @@ -1068,6 +1090,8 @@ Bool MiniAudioManager::isPlayingLowerPriority(AudioEventRTS *event) const
//-------------------------------------------------------------------------------------------------
Bool MiniAudioManager::killLowestPrioritySoundImmediately(AudioEventRTS *event)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
AudioEventRTS *lowestPriorityEvent = findLowestPrioritySound(event);
if (!lowestPriorityEvent) return FALSE;

Expand All @@ -1086,6 +1110,8 @@ Bool MiniAudioManager::killLowestPrioritySoundImmediately(AudioEventRTS *event)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::adjustVolumeOfPlayingAudio(AsciiString eventName, Real newVolume)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
for (auto it = m_playingSounds.begin(); it != m_playingSounds.end(); ++it) {
PlayingAudio *playing = *it;
if (playing && playing->m_audioEventRTS && playing->m_audioEventRTS->getEventName() == eventName) {
Expand All @@ -1098,6 +1124,8 @@ void MiniAudioManager::adjustVolumeOfPlayingAudio(AsciiString eventName, Real ne
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::removePlayingAudio(AsciiString eventName)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
for (auto it = m_playingSounds.begin(); it != m_playingSounds.end(); ) {
PlayingAudio *playing = *it;
if (playing && playing->m_audioEventRTS && playing->m_audioEventRTS->getEventName() == eventName) {
Expand All @@ -1111,6 +1139,8 @@ void MiniAudioManager::removePlayingAudio(AsciiString eventName)
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::removeAllDisabledAudio(void)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
for (auto it = m_playingSounds.begin(); it != m_playingSounds.end(); ) {
PlayingAudio *playing = *it;
if (playing && playing->m_audioEventRTS && playing->m_audioEventRTS->getVolume() == 0.0f) {
Expand Down Expand Up @@ -1266,6 +1296,8 @@ void MiniAudioManager::setSpeakerSurround(Bool surround)
//-------------------------------------------------------------------------------------------------
Real MiniAudioManager::getFileLengthMS(AsciiString strToLoad) const
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
if (strToLoad.isEmpty()) return 0.0f;

static ma_vfs_callbacks vfs = {};
Expand Down Expand Up @@ -1299,6 +1331,8 @@ Real MiniAudioManager::getFileLengthMS(AsciiString strToLoad) const
//-------------------------------------------------------------------------------------------------
void MiniAudioManager::closeAnySamplesUsingFile(const void *fileToClose)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
// miniaudio manages file lifecycle internally after decoding
}

Expand Down
16 changes: 16 additions & 0 deletions Core/GameEngineDevice/Source/MiniAudioDevice/MiniAudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "MiniAudioDevice/MiniAudioStream.h"
#include "Lib/BaseType.h"
// GeneralsX @bugfix meerzulee 19/07/2026 ScopedFPUGuard for FP env guards on audio entry points (see #215)
#include "GameLogic/FPUControl.h"
#include <cstring>

static ma_result MiniAudioStream_read(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead)
Expand Down Expand Up @@ -71,6 +73,8 @@ MiniAudioStream::~MiniAudioStream()

bool MiniAudioStream::bufferData(uint8_t *data, size_t data_size, ma_format format, int samplerate, int channels)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
if (data_size == 0) return false;

std::lock_guard<std::mutex> lock(m_mutex);
Expand All @@ -94,6 +98,8 @@ bool MiniAudioStream::isPlaying()

void MiniAudioStream::update()
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
bool shouldCreate = false;
{
std::lock_guard<std::mutex> lock(m_mutex);
Expand All @@ -109,6 +115,8 @@ void MiniAudioStream::update()

void MiniAudioStream::reset()
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
if (m_sound) {
ma_sound_stop(m_sound);
ma_sound_uninit(m_sound);
Expand All @@ -129,6 +137,8 @@ void MiniAudioStream::reset()

void MiniAudioStream::play()
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
std::lock_guard<std::mutex> lock(m_mutex);
m_playing = true;
if (m_sound) ma_sound_start(m_sound);
Expand Down Expand Up @@ -163,18 +173,24 @@ void MiniAudioStream::createSound()

void MiniAudioStream::pause()
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
m_playing = false;
if (m_sound) ma_sound_stop(m_sound);
}

void MiniAudioStream::stop()
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
pause();
reset();
}

void MiniAudioStream::setVolume(float vol)
{
// GeneralsX @bugfix meerzulee 19/07/2026 FP env guard for audio entry point (see #215)
ScopedFPUGuard fpuGuard;
if (m_sound) ma_sound_set_volume(m_sound, vol);
}

Expand Down
Loading
Loading