Skip to content

Commit dbd3ce7

Browse files
Synchronize changes from 1.6 branch [ci skip]
feae02e Minor audio related changes d68171c Fix heap corruption crash (No dialog) @ GTA SA 0x4fc66f: Engine sound type 4: Accelerate or type 5/Gear change 5c0c283 Addendum to 651cea5 e75b073 Fix audio crash
2 parents cb940c2 + feae02e commit dbd3ce7

File tree

4 files changed

+19
-28
lines changed

4 files changed

+19
-28
lines changed

Client/core/CrashHandler.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -708,31 +708,21 @@ void __cdecl AbortSignalHandler([[maybe_unused]] int signal) noexcept
708708
CONTEXT* pCtx = nullptr;
709709
EXCEPTION_POINTERS exPtrs{};
710710

711-
if (BuildExceptionContext(exPtrs, pExRecord, pCtx, EXCEPTION_NONCONTINUABLE_EXCEPTION))
711+
PFNCHFILTFN callback = g_pfnCrashCallback.load(std::memory_order_acquire);
712+
713+
if (callback != nullptr && BuildExceptionContext(exPtrs, pExRecord, pCtx, EXCEPTION_NONCONTINUABLE_EXCEPTION))
712714
{
713-
PFNCHFILTFN callback = g_pfnCrashCallback.load(std::memory_order_acquire);
714-
if (callback != nullptr)
715-
{
716-
LogHandlerEvent(DEBUG_PREFIX_PURECALL, "Calling crash handler callback");
715+
LogHandlerEvent(DEBUG_PREFIX_PURECALL, "Calling crash handler callback");
717716

718-
try
719-
{
720-
callback(&exPtrs);
721-
}
722-
catch (...)
723-
{
724-
LogHandlerEvent(DEBUG_PREFIX_PURECALL, "Exception in crash handler callback");
725-
}
717+
try
718+
{
719+
callback(&exPtrs);
726720
}
727-
else
721+
catch (...)
728722
{
729-
LogHandlerEvent(DEBUG_PREFIX_PURECALL, "No crash handler callback available");
723+
LogHandlerEvent(DEBUG_PREFIX_PURECALL, "Exception in crash handler callback");
730724
}
731725
}
732-
else
733-
{
734-
LogHandlerEvent(DEBUG_PREFIX_PURECALL, "Failed to allocate exception structures");
735-
}
736726

737727
if (pCtx != nullptr)
738728
{
@@ -1346,7 +1336,7 @@ static bool BuildExceptionContext(EXCEPTION_POINTERS& outExPtrs, EXCEPTION_RECOR
13461336

13471337
PFNCHFILTFN callback = g_pfnCrashCallback.load(std::memory_order_acquire);
13481338

1349-
if (BuildExceptionContext(exPtrs, pExRecord, pCtx, CPP_EXCEPTION_CODE) && callback != nullptr)
1339+
if (callback != nullptr && BuildExceptionContext(exPtrs, pExRecord, pCtx, CPP_EXCEPTION_CODE))
13501340
{
13511341
SafeDebugOutput(DEBUG_PREFIX_CPP "Calling crash handler callback\n");
13521342

Client/mods/deathmatch/logic/CClientSound.cpp

Lines changed: 6 additions & 7 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
}
@@ -155,7 +154,7 @@ bool CClientSound::Create()
155154
// Load file/start connect
156155
if (!m_pAudio->BeginLoadingMedia())
157156
{
158-
delete m_pAudio;
157+
m_pAudio->Destroy();
159158
m_pAudio = nullptr;
160159
return false;
161160
}

Client/mods/deathmatch/logic/CClientSound.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class CClientSound final : public CClientEntity
127127
static AudioBufferDeleter ForExternalReference() noexcept { return AudioBufferDeleter(&NoopImpl); }
128128

129129
private:
130-
static void DeleteArrayImpl(void* ptr) noexcept { ::operator delete[](ptr); }
130+
static void DeleteArrayImpl(void* ptr) noexcept { delete[] static_cast<uint8_t*>(ptr); }
131131
static void FreeImpl(void* ptr) noexcept { std::free(ptr); }
132132
static void NoopImpl(void*) noexcept {}
133133

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)