Skip to content

Commit

Permalink
Fixed a memory corruption bug in Android Display plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
znakeeye committed Feb 20, 2025
1 parent 7b3ec94 commit 066e0b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
16 changes: 8 additions & 8 deletions code/plugins/Display/android/orxDisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,28 +574,28 @@ static orxU32 orxAndroid_Display_GetPhysicalRefreshRate()

static void orxAndroid_Display_InitSupportedRefreshRates()
{
orxU32 u32NativeRateCount;
orxS32 s32NativeRateCount;

/* Clears supported refresh rates */
orxMemory_Zero(sstDisplay.acSupportedRates, sizeof(sstDisplay.acSupportedRates) * sizeof(char));

u32NativeRateCount = SwappyGL_getSupportedRefreshPeriodsNS(nullptr, 0);
s32NativeRateCount = SwappyGL_getSupportedRefreshPeriodsNS(nullptr, 0);

/* Checks */
orxASSERT(u32NativeRateCount > 0);
orxASSERT(sstDisplay.u32PhysicalRefreshRate > 0);

if(u32NativeRateCount > 0)
if(s32NativeRateCount > 0)
{
orxU32 d, i;
orxS32 i;
orxU32 d;
uint64_t *pu64RefreshPeriods;

/* Gets natively supported refresh periods (ns) */
pu64RefreshPeriods = (uint64_t*)orxMemory_Allocate(u32NativeRateCount * sizeof(uint64_t), orxMEMORY_TYPE_TEMP);
SwappyGL_getSupportedRefreshPeriodsNS(pu64RefreshPeriods, u32NativeRateCount);
pu64RefreshPeriods = (uint64_t*)orxMemory_Allocate(s32NativeRateCount * sizeof(uint64_t), orxMEMORY_TYPE_TEMP);
SwappyGL_getSupportedRefreshPeriodsNS(pu64RefreshPeriods, s32NativeRateCount);

/* Finds all supported rates */
for(i = 0; i < u32NativeRateCount; i++)
for(i = 0; i < s32NativeRateCount; i++)
{
orxU32 u32RefreshRate = orxDISPLAY_NANO_INVERSE(pu64RefreshPeriods[i]);
if(u32RefreshRate > sstDisplay.u32PhysicalRefreshRate)
Expand Down
14 changes: 3 additions & 11 deletions code/plugins/Physics/LiquidFun/orxPhysics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3551,25 +3551,21 @@ extern "C" orxSTATUS orxFASTCALL orxPhysics_LiquidFun_Init()
if(sstPhysics.pstEventBank != orxNULL)
{
orxBank_Delete(sstPhysics.pstEventBank);
sstPhysics.pstEventBank = orxNULL;
}

if(sstPhysics.pstBodyBank != orxNULL)
{
orxBank_Delete(sstPhysics.pstBodyBank);
sstPhysics.pstBodyBank = orxNULL;
}

/* Unregisters update function */
orxClock_Unregister(pstClock, orxPhysics_LiquidFun_Update);

/* Deletes listeners */
delete sstPhysics.poContactListener;
sstPhysics.poContactListener = orxNULL;

/* Deletes world */
delete sstPhysics.poWorld;
sstPhysics.poWorld = orxNULL;

/* Unregisters update function */
orxClock_Unregister(pstClock, orxPhysics_LiquidFun_Update);

/* Updates result */
eResult = orxSTATUS_FAILURE;
Expand All @@ -3579,11 +3575,9 @@ extern "C" orxSTATUS orxFASTCALL orxPhysics_LiquidFun_Init()
{
/* Deletes listeners */
delete sstPhysics.poContactListener;
sstPhysics.poContactListener = orxNULL;

/* Deletes world */
delete sstPhysics.poWorld;
sstPhysics.poWorld = orxNULL;

/* Updates result */
eResult = orxSTATUS_FAILURE;
Expand All @@ -3593,11 +3587,9 @@ extern "C" orxSTATUS orxFASTCALL orxPhysics_LiquidFun_Init()
{
/* Deletes listeners */
delete sstPhysics.poContactListener;
sstPhysics.poContactListener = orxNULL;

/* Deletes world */
delete sstPhysics.poWorld;
sstPhysics.poWorld = orxNULL;

/* Updates result */
eResult = orxSTATUS_FAILURE;
Expand Down

0 comments on commit 066e0b0

Please sign in to comment.