Skip to content

Commit feae02e

Browse files
committed
Minor audio related changes
1 parent d68171c commit feae02e

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Client/mods/deathmatch/logic/CClientSound.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,14 @@ void CClientSound::AdoptBuffer(void* pMemory, unsigned int uiLength, AudioBuffer
5959
return;
6060
}
6161

62-
if (!m_Buffer || m_Buffer.get() != pMemory)
62+
// Always release the old buffer before adopting a new one, even if the pointer is the same
63+
// This prevents deleter mismatch issues (e.g., mixing new[]/delete[] with malloc/free)
64+
if (m_Buffer)
6365
{
64-
m_Buffer = BufferPtr(pMemory, std::move(deleter));
65-
}
66-
else
67-
{
68-
m_Buffer.get_deleter() = std::move(deleter);
66+
ReleaseBuffer();
6967
}
7068

69+
m_Buffer = BufferPtr(pMemory, std::move(deleter));
7170
m_uiBufferLength = uiLength;
7271
m_strPath.clear();
7372
}

Client/mods/deathmatch/logic/CClientSoundManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ CClientSound* CClientSoundManager::PlaySound2D(const SString& strSound, bool bIs
141141
memcpy(pMemory, strSound.data(), size);
142142
if (pSound->Play((void*)pMemory, size, bLoop))
143143
return pSound;
144+
// Note: pMemory is already owned by pSound via AdoptBuffer, don't delete it here
144145
}
145146
else if (pSound->Play(strSound, bLoop))
146147
return pSound;
@@ -180,6 +181,7 @@ CClientSound* CClientSoundManager::PlaySound3D(const SString& strSound, bool bIs
180181
pSound->SetPosition(vecPosition);
181182
return pSound;
182183
}
184+
// Note: pMemory is already owned by pSound via AdoptBuffer, don't delete it here
183185
}
184186
else if (pSound->Play3D(strSound, bLoop))
185187
{

0 commit comments

Comments
 (0)