Skip to content

Commit 37ada0b

Browse files
committed
Add dispose
1 parent 687ba3b commit 37ada0b

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

runtimes/talos/src/main/java/com/talosvfx/talos/runtime/scene/GameObjectRenderer.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.badlogic.gdx.graphics.g2d.TextureRegion;
1111
import com.badlogic.gdx.math.Vector2;
1212
import com.badlogic.gdx.utils.Array;
13+
import com.badlogic.gdx.utils.Disposable;
1314
import com.badlogic.gdx.utils.GdxRuntimeException;
1415
import com.esotericsoftware.spine.Bone;
1516
import com.talosvfx.talos.runtime.scene.components.*;
@@ -19,7 +20,7 @@
1920

2021
import java.util.Comparator;
2122

22-
public class GameObjectRenderer {
23+
public class GameObjectRenderer implements Disposable {
2324
private ComponentRenderer<SpriteRendererComponent> spriteRenderer;
2425
private ComponentRenderer<MapComponent> mapRenderer;
2526
private ComponentRenderer<ParticleComponent<?>> particleRenderer;
@@ -39,9 +40,13 @@ public class GameObjectRenderer {
3940

4041

4142
private static TextureRegion brokenRegion;
43+
private static Texture brokenTexture;
4244

4345
public GameObjectRenderer () {
44-
brokenRegion = new TextureRegion(new Texture(Gdx.files.classpath("missing.png")));
46+
if (brokenRegion == null) {
47+
brokenTexture = new Texture(Gdx.files.classpath("missing.png"));
48+
brokenRegion = new TextureRegion(brokenTexture);
49+
}
4550

4651
spriteRenderer = createSpriteRenderer();
4752
mapRenderer = createMapRenderer();
@@ -447,4 +452,13 @@ public void setCamera (Camera camera) {
447452
public void setSkipUpdates (boolean skipUpdates) {
448453
this.skipUpdates = skipUpdates;
449454
}
455+
456+
@Override
457+
public void dispose () {
458+
if (brokenRegion != null) {
459+
brokenTexture.dispose();
460+
brokenRegion = null;
461+
brokenTexture = null;
462+
}
463+
}
450464
}

0 commit comments

Comments
 (0)