mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 09:39:43 +01:00
Fix enemy movement types 10/12 causing memory leaks
If spawned as a custom enemy (createentity entry 56), or spawned outside of the rooms they spawn in in the main game, they will repeatedly clone themselves every frame, which profusely leaks memory. In fact it quickly causes a crash in 2.2 and previous, but 2.3 fixes that crash, so it just keeps spawning enemies endlessly, which eventually lags the game, and eventually can out-of-memory your system (bad!). The problem is those movement types rely on entclass::setenemyroom() to change their `behave` to be 11 or 13. Else, the new entity created will still have `behave` 10 or 12, which will create ANOTHER entity in the same way, and so on, and so forth. So to fix this, just make it so if an enemy is still `behave` 10 or 12 by the end, then, just set it to -1. That way it'll stay still and won't cause any harm. I considered setting the `behave` to 11 or 13 respectively, but, that's probably going farther than just fixing a memory leak, and anyways, it's not that much useful for me as a custom level maker, and the entities spawned aren't really controllable.
This commit is contained in:
parent
7c18123327
commit
4f881b9e26
1 changed files with 11 additions and 0 deletions
|
@ -1204,6 +1204,15 @@ int entityclass::crewcolour( int t )
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void entityclonefix(entclass* entity)
|
||||
{
|
||||
if (entity->behave == 10 || entity->behave == 12)
|
||||
{
|
||||
/* Fix memory leak */
|
||||
entity->behave = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void entityclass::createentity(int xp, int yp, int t, int meta1, int meta2, int p1, int p2, int p3, int p4)
|
||||
{
|
||||
k = entities.size();
|
||||
|
@ -1324,6 +1333,7 @@ void entityclass::createentity(int xp, int yp, int t, int meta1, int meta2, int
|
|||
else
|
||||
{
|
||||
entity.setenemyroom(game.roomx, game.roomy);
|
||||
entityclonefix(&entity);
|
||||
}
|
||||
break;
|
||||
case 2: //A moving platform
|
||||
|
@ -2094,6 +2104,7 @@ void entityclass::createentity(int xp, int yp, int t, int meta1, int meta2, int
|
|||
entity.colour = 18;
|
||||
}
|
||||
|
||||
entityclonefix(&entity);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue