diff --git a/src/itdelatrisu/opsu/GameData.java b/src/itdelatrisu/opsu/GameData.java index e35a079e..9138d725 100644 --- a/src/itdelatrisu/opsu/GameData.java +++ b/src/itdelatrisu/opsu/GameData.java @@ -42,7 +42,7 @@ import org.newdawn.slick.Animation; import org.newdawn.slick.Color; import org.newdawn.slick.Graphics; import org.newdawn.slick.Image; -import yugecin.opsudance.Dancer; +import yugecin.opsudance.utils.SlickUtil; /** * Holds game data and renders all related elements. @@ -101,8 +101,16 @@ public class GameData { * This does NOT destroy images, so be careful of memory leaks! */ public static void clearReferences() { - for (Grade grade : Grade.values()) + for (Grade grade : Grade.values()) { grade.menuImage = null; + } + } + + public static void destroyImages() { + for (Grade grade : Grade.values()) { + SlickUtil.destroyImage(grade.menuImage); + grade.menuImage = null; + } } /** diff --git a/src/itdelatrisu/opsu/GameImage.java b/src/itdelatrisu/opsu/GameImage.java index de479156..cd1dd463 100644 --- a/src/itdelatrisu/opsu/GameImage.java +++ b/src/itdelatrisu/opsu/GameImage.java @@ -28,6 +28,7 @@ import org.newdawn.slick.Animation; import org.newdawn.slick.Image; import org.newdawn.slick.SlickException; import org.newdawn.slick.util.ResourceLoader; +import yugecin.opsudance.utils.SlickUtil; /** * Game images. @@ -461,37 +462,18 @@ public enum GameImage { } } - public static void destroyAll() { + public static void destroyImages() { for (GameImage img : GameImage.values()) { - destroyAll(img.defaultImages); - destroyImage(img.defaultImage); - destroyAll(img.skinImages); - destroyImage(img.skinImage); + SlickUtil.destroyImages(img.defaultImages); + SlickUtil.destroyImage(img.defaultImage); + SlickUtil.destroyImages(img.skinImages); + SlickUtil.destroyImage(img.skinImage); img.isSkinned = false; img.defaultImages = img.skinImages = null; img.defaultImage = img.skinImage = null; } } - public static void destroyAll(Image[] imgs) { - if (imgs == null) { - return; - } - for (Image i : imgs) { - destroyImage(i); - } - } - - public static void destroyImage(Image image) { - if (image == null) { - return; - } - try { - image.destroy(); - } catch (SlickException ignored) { - } - } - /** * Returns the bitmask image type from a type string. * @param type the type string diff --git a/src/itdelatrisu/opsu/beatmap/Beatmap.java b/src/itdelatrisu/opsu/beatmap/Beatmap.java index a87cc236..55a34ab5 100644 --- a/src/itdelatrisu/opsu/beatmap/Beatmap.java +++ b/src/itdelatrisu/opsu/beatmap/Beatmap.java @@ -22,6 +22,7 @@ import itdelatrisu.opsu.Options; import java.io.File; import java.util.ArrayList; +import java.util.Collection; import java.util.LinkedList; import java.util.Map; @@ -59,6 +60,14 @@ public class Beatmap implements Comparable { */ public static void clearBackgroundImageCache() { bgImageCache.clear(); } + public static void destroyBackgroundImageCache() { + Collection values = bgImageCache.values(); + for (ImageLoader value : values) { + value.destroy(); + } + bgImageCache.clear(); + } + /** The OSU File object associated with this beatmap. */ private File file; diff --git a/src/yugecin/opsudance/core/DisplayContainer.java b/src/yugecin/opsudance/core/DisplayContainer.java index 4ede5648..6c6242fd 100644 --- a/src/yugecin/opsudance/core/DisplayContainer.java +++ b/src/yugecin/opsudance/core/DisplayContainer.java @@ -17,9 +17,11 @@ */ package yugecin.opsudance.core; +import itdelatrisu.opsu.GameData; import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.Options; import itdelatrisu.opsu.audio.MusicController; +import itdelatrisu.opsu.beatmap.Beatmap; import itdelatrisu.opsu.ui.Fonts; import org.lwjgl.Sys; import org.lwjgl.openal.AL; @@ -213,7 +215,9 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen public void teardown() { InternalTextureLoader.get().clear(); - GameImage.destroyAll(); + GameImage.destroyImages(); + GameData.Grade.destroyImages(); + Beatmap.destroyBackgroundImageCache(); Display.destroy(); } diff --git a/src/yugecin/opsudance/utils/SlickUtil.java b/src/yugecin/opsudance/utils/SlickUtil.java new file mode 100644 index 00000000..1123caf0 --- /dev/null +++ b/src/yugecin/opsudance/utils/SlickUtil.java @@ -0,0 +1,44 @@ +/* + * opsu!dance - fork of opsu! with cursordance auto + * Copyright (C) 2017 yugecin + * + * opsu!dance is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * opsu!dance is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with opsu!dance. If not, see . + */ +package yugecin.opsudance.utils; + +import org.newdawn.slick.Image; +import org.newdawn.slick.SlickException; + +public class SlickUtil { + + public static void destroyImages(Image[] imgs) { + if (imgs == null) { + return; + } + for (Image i : imgs) { + destroyImage(i); + } + } + + public static void destroyImage(Image image) { + if (image == null) { + return; + } + try { + image.destroy(); + } catch (SlickException ignored) { + } + } + +}