Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class MilesAudioManager : public AudioManager
UnsignedInt m_selectedProvider;
UnsignedInt m_lastProvider;
UnsignedInt m_selectedSpeakerType;
Bool m_providerInitializing;

AsciiString m_pref3DProvider;
AsciiString m_prefSpeaker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
m_delayFilter(NULL),
m_binkHandle(NULL),
m_pref3DProvider(AsciiString::TheEmptyString),
m_prefSpeaker(AsciiString::TheEmptyString)
m_prefSpeaker(AsciiString::TheEmptyString),
m_providerInitializing(FALSE)
{
m_audioCache = NEW AudioFileCache;
}
Expand Down Expand Up @@ -1225,6 +1226,12 @@
//-------------------------------------------------------------------------------------------------
H3DSAMPLE MilesAudioManager::getFirst3DSample( AudioEventRTS *event )
{
// Don't allocate 3D samples while provider is still initializing
// This prevents race conditions where samples are used before DirectSound buffers are fully set up
if (m_providerInitializing) {
return NULL;
}

if (m_available3DSamples.begin() != m_available3DSamples.end()) {
H3DSAMPLE retSample = *m_available3DSamples.begin();
m_available3DSamples.erase(m_available3DSamples.begin());
Expand Down Expand Up @@ -1722,6 +1729,10 @@
{
providerNdx = getProviderIndex( "Miles Fast 2D Positional Audio" );
}

// Set initialization flag to prevent samples from being used before provider is ready
m_providerInitializing = TRUE;

success = AIL_open_3D_provider( m_provider3D[providerNdx].id ) == 0;

//if (providerNdx < m_providerCount)
Expand All @@ -1743,14 +1754,31 @@
{
m_selectedProvider = providerNdx;

// Create listener first to ensure provider has proper context
createListener();

// Force the provider to complete internal initialization by updating listener position
// This ensures DirectSound buffers are fully set up before sample allocation
if (m_listener) {
AIL_update_3D_position(m_listener);

Check failure on line 1763 in Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-debug+e

'AIL_update_3D_position': identifier not found

Check failure on line 1763 in Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32+e

'AIL_update_3D_position': identifier not found

Check failure on line 1763 in Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp

View workflow job for this annotation

GitHub Actions / Build GeneralsMD / win32-profile+e

'AIL_update_3D_position': identifier not found
}

// Now it's safe to initialize sample pools
initSamplePools();

createListener();
setSpeakerType(m_selectedSpeakerType);
if (TheVideoPlayer)
{
TheVideoPlayer->notifyVideoPlayerOfNewProvider(TRUE);
}

// Clear initialization flag - provider is now fully ready
m_providerInitializing = FALSE;
}
else
{
// Failed to open provider, clear initialization flag
m_providerInitializing = FALSE;
}
}

Expand Down
Loading