mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Permanently fix aligned memalloc crash
It was still crashing as the thisptr should actually be passed into the alloc callback. Changed and the function call is now identical to engine's impl. Tested in Debug, Profile and Release, Release has also been tested with LTCG.
This commit is contained in:
parent
cb2850f938
commit
8cb46354e6
@ -7,13 +7,23 @@
|
||||
class CAlignedMemAlloc
|
||||
{
|
||||
public:
|
||||
static void* Alloc(size_t nSize, size_t nAlignment = 0);
|
||||
static void Free(void* pMem);
|
||||
// Passed explicit parameters for 'this' pointer; the game expects one,
|
||||
// albeit unused. Do NOT optimize this away!
|
||||
typedef void* (*FnAlloc_t)(CAlignedMemAlloc* thisptr, size_t nSize, size_t nAlignment);
|
||||
typedef void (*FnFree_t)(CAlignedMemAlloc* thisptr, void* pMem);
|
||||
|
||||
CAlignedMemAlloc(FnAlloc_t pAllocCallback, FnFree_t pFreeCallback);
|
||||
|
||||
inline void* Alloc(size_t nSize, size_t nAlign = 0)
|
||||
{
|
||||
return m_pAllocCallback(this, nSize, nAlign);
|
||||
}
|
||||
inline void Free(void* pMem)
|
||||
{
|
||||
m_pFreeCallback(this, pMem);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef void* (*FnAlloc_t)(size_t nSize, size_t nAlignment);
|
||||
typedef void (*FnFree_t)(void* pMem);
|
||||
|
||||
FnAlloc_t m_pAllocCallback;
|
||||
FnFree_t m_pFreeCallback;
|
||||
};
|
||||
|
@ -6,23 +6,14 @@
|
||||
#include "tier0/tslist.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: alloc aligned memory
|
||||
// Input : nSize -
|
||||
// nPad -
|
||||
// Output : pointer to allocated aligned memory
|
||||
// Purpose: constructor
|
||||
// Input : *pAllocCallback -
|
||||
// *pFreeCallback -
|
||||
//-----------------------------------------------------------------------------
|
||||
void* CAlignedMemAlloc::Alloc(size_t nSize, size_t nAlignment)
|
||||
CAlignedMemAlloc::CAlignedMemAlloc(FnAlloc_t pAllocCallback, FnFree_t pFreeCallback)
|
||||
{
|
||||
return g_pAlignedMemAlloc->m_pAllocCallback(nSize, nAlignment);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: free aligned memory
|
||||
// Input : pMem -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CAlignedMemAlloc::Free(void* pMem)
|
||||
{
|
||||
g_pAlignedMemAlloc->m_pFreeCallback(pMem);
|
||||
m_pAllocCallback = pAllocCallback;
|
||||
m_pFreeCallback = pFreeCallback;
|
||||
}
|
||||
|
||||
CAlignedMemAlloc* g_pAlignedMemAlloc;
|
||||
|
Loading…
x
Reference in New Issue
Block a user