Skip to content

Commit

Permalink
Fix various memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Dec 11, 2023
1 parent 05e9c98 commit 1eafbeb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/src/mindustry/client/ClientLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mindustry.client

import arc.*
import arc.Core.*
import arc.graphics.g2d.SortedSpriteBatch
import arc.math.geom.*
import arc.struct.*
import arc.util.*
Expand Down Expand Up @@ -262,5 +263,9 @@ class ClientLogic {
camera.bounds(cameraBounds)
cameraBounds.grow(2 * tilesizeF)
}

Events.on(ResetEvent::class.java) {
(batch as? SortedSpriteBatch)?.reset()
}
}
}
4 changes: 4 additions & 0 deletions core/src/mindustry/entities/Fires.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ public static void register(Fire fire){
map.put(fire.tile.pos(), fire);
}
}

static { // FINISHME: Temp hack as fire not being cleared keeps tiles in memory forever. Remove in v147 when anuke fixes it
Events.on(ResetEvent.class, e -> map.clear());
}
}
5 changes: 5 additions & 0 deletions core/src/mindustry/entities/Puddles.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mindustry.entities;

import arc.*;
import arc.math.*;
import arc.struct.*;
import arc.util.*;
Expand Down Expand Up @@ -108,6 +109,10 @@ public static void register(Puddle puddle){
map.put(puddle.tile().pos(), puddle);
}

static { // FINISHME: Temp hack as puddles not being cleared keeps tiles in memory forever. Remove in v147 when anuke fixes it
Events.on(EventType.ResetEvent.class, e -> map.clear());
}

/** Reacts two liquids together at a location. */
private static float reactPuddle(Liquid dest, Liquid liquid, float amount, Tile tile, float x, float y){
if(dest == null) return 0f;
Expand Down
4 changes: 4 additions & 0 deletions core/src/mindustry/entities/comp/PlayerComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ public void remove(){
if(!unit.isNull()){
clearUnit();
}

// null these out to prevent long-lived player objects (for example, Moderation.leaves) from holding onto units with logic controllers that will hold all of their neighbors
lastReadUnit = Nulls.unit;
justSwitchFrom = justSwitchTo = null;
}

public void team(Team team){
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ org.gradle.internal.http.connectionTimeout=100000
#kapt.verbose=true
# For some reason kapt ir is just completely broken for us. I don't know why.
kapt.use.jvm.ir=false
archash=a5d9b11fe5ffc147f3a71d525b9c1532f8584b5d
archash=2863938b5e8a4756428faa0327d7616dcbc8511b

0 comments on commit 1eafbeb

Please sign in to comment.