mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Fix aligned memalloc crash when compiled with LTCG
Crash occurred as the arguments to the alloc/free callbacks would involve the 'this' pointer, and therefore, the registers would shift and misalign. The fix is to just make the functions static and call the pointers directly from the singleton exposed by the engine. Additional cleanup has been performed by adding typedefs for the function pointers.
This commit is contained in:
parent
a90302f09f
commit
248efc114b
@ -7,12 +7,15 @@
|
||||
class CAlignedMemAlloc
|
||||
{
|
||||
public:
|
||||
void* Alloc(size_t nSize, size_t nAlignment = 0);
|
||||
void Free(void* pMem);
|
||||
static void* Alloc(size_t nSize, size_t nAlignment = 0);
|
||||
static void Free(void* pMem);
|
||||
|
||||
private:
|
||||
void* m_pAllocCallback;
|
||||
void* m_pFreeCallback;
|
||||
typedef void* (*FnAlloc_t)(size_t nSize, size_t nAlignment);
|
||||
typedef void (*FnFree_t)(void* pMem);
|
||||
|
||||
FnAlloc_t m_pAllocCallback;
|
||||
FnFree_t m_pFreeCallback;
|
||||
};
|
||||
|
||||
extern CAlignedMemAlloc* g_pAlignedMemAlloc;
|
||||
|
@ -13,7 +13,7 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
void* CAlignedMemAlloc::Alloc(size_t nSize, size_t nAlignment)
|
||||
{
|
||||
return ((void* (*)(size_t, size_t))m_pAllocCallback)(nSize, nAlignment);
|
||||
return g_pAlignedMemAlloc->m_pAllocCallback(nSize, nAlignment);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -22,7 +22,7 @@ void* CAlignedMemAlloc::Alloc(size_t nSize, size_t nAlignment)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CAlignedMemAlloc::Free(void* pMem)
|
||||
{
|
||||
((void (*)(void*))m_pFreeCallback)(pMem);
|
||||
g_pAlignedMemAlloc->m_pFreeCallback(pMem);
|
||||
}
|
||||
|
||||
CAlignedMemAlloc* g_pAlignedMemAlloc;
|
||||
|
Loading…
x
Reference in New Issue
Block a user