FIXED MEMORY LEAK WOOHOO
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
2193
|
||||
2199
|
||||
@@ -103,14 +103,10 @@ class MainMenuState extends MusicBeatState
|
||||
|
||||
if (!selectedSomethin)
|
||||
{
|
||||
if (canAccessDebugMenus) {
|
||||
if (canAccessDebugMenus)
|
||||
if (FlxG.keys.justPressed.SEVEN)
|
||||
FlxG.switchState(new funkin.desktop.DesktopMain());
|
||||
|
||||
if (FlxG.keys.justPressed.F1)
|
||||
funkin.multitasking.MultiTaskingHandler.openWindow("FreeplayState", new FreeplayState());
|
||||
}
|
||||
|
||||
if (controls.UP_P)
|
||||
changeItem(-1);
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package funkin.multitasking;
|
||||
|
||||
import flixel.FlxState;
|
||||
import flixel.FlxG;
|
||||
|
||||
class MultiTaskingHandler {
|
||||
public static var openedWindows:Array<StateWindow> = [];
|
||||
|
||||
public static function init() {
|
||||
FlxG.signals.postUpdate.add(update);
|
||||
// FlxG.signals.preDraw.add(draw);
|
||||
}
|
||||
|
||||
public static function openWindow(name:String, state:MusicBeatState) {
|
||||
var window = new StateWindow(name, state);
|
||||
openedWindows.push(window);
|
||||
}
|
||||
|
||||
public static function update() {
|
||||
for(window in openedWindows) {
|
||||
window.update(FlxG.elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
public static function draw() {
|
||||
for(window in openedWindows) {
|
||||
window.draw();
|
||||
}
|
||||
}
|
||||
|
||||
public static function closeWindow(window:StateWindow) {
|
||||
openedWindows.remove(window);
|
||||
|
||||
window.window.close();
|
||||
window.state.destroy();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
package funkin.multitasking;
|
||||
|
||||
import flixel.system.frontEnds.BitmapFrontEnd;
|
||||
import openfl.Lib;
|
||||
import openfl.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flixel.math.FlxPoint;
|
||||
import lime.ui.WindowAttributes;
|
||||
import lime.app.Application;
|
||||
import lime.ui.Window;
|
||||
import flixel.FlxState;
|
||||
import flixel.FlxCamera;
|
||||
import flixel.FlxG;
|
||||
|
||||
class StateWindow extends Sprite {
|
||||
public var window:Window;
|
||||
public var state:MusicBeatState;
|
||||
public var camera:FlxCamera;
|
||||
public var cameras:Array<FlxCamera>;
|
||||
public var camerasDefault:Array<FlxCamera>;
|
||||
public var bmapFrontEnd:BitmapFrontEnd = new BitmapFrontEnd();
|
||||
|
||||
public function new(windowName:String, state:MusicBeatState) {
|
||||
super();
|
||||
|
||||
var windowAttributes:WindowAttributes = {
|
||||
width: FlxG.width,
|
||||
height: FlxG.height,
|
||||
resizable: true
|
||||
};
|
||||
window = Application.current.createWindow(windowAttributes);
|
||||
window.title = windowName;
|
||||
window.stage.color = 0x000000;
|
||||
window.stage.scaleMode = NO_SCALE;
|
||||
window.stage.align = TOP_LEFT;
|
||||
window.onClose.add(function() {
|
||||
MultiTaskingHandler.closeWindow(this);
|
||||
});
|
||||
|
||||
window.stage.addChild(this);
|
||||
|
||||
camera = new FlxCamera();
|
||||
cameras = [camera];
|
||||
camerasDefault = [camera];
|
||||
|
||||
state.parentWindow = this;
|
||||
this.state = state;
|
||||
|
||||
beforeStateShit();
|
||||
state.create();
|
||||
state.createPost();
|
||||
afterStateShit();
|
||||
|
||||
|
||||
}
|
||||
|
||||
var oldSize = new FlxPoint(FlxG.width, FlxG.height);
|
||||
var oldCamList:Array<FlxCamera>;
|
||||
var oldCamDefaults:Array<FlxCamera>;
|
||||
var oldCam:FlxCamera;
|
||||
var oldState:FlxState;
|
||||
var oldFrontEnd:BitmapFrontEnd;
|
||||
|
||||
public function beforeStateShit() {
|
||||
oldSize.set(FlxG.width, FlxG.height);
|
||||
|
||||
@:privateAccess {
|
||||
FlxG.width = 1280;
|
||||
FlxG.height = 720;
|
||||
|
||||
oldCamDefaults = FlxG.cameras.defaults;
|
||||
oldCamList = FlxG.cameras.list;
|
||||
oldCam = FlxG.camera;
|
||||
|
||||
FlxCamera._defaultCameras = FlxG.cameras.defaults = camerasDefault;
|
||||
FlxG.cameras.list = cameras;
|
||||
FlxG.camera = camera;
|
||||
|
||||
oldState = FlxG.game._state;
|
||||
FlxG.game._state = state;
|
||||
|
||||
|
||||
if (this.numChildren != cameras.length) {
|
||||
trace("readding cameras...");
|
||||
while(this.numChildren > 0)
|
||||
removeChild(getChildAt(0));
|
||||
|
||||
for(c in cameras) {
|
||||
addChild(c.flashSprite);
|
||||
c.flashSprite.x = c.flashSprite.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
oldFrontEnd = FlxG.bitmap;
|
||||
FlxG.bitmap = bmapFrontEnd;
|
||||
}
|
||||
}
|
||||
|
||||
public function afterStateShit() {
|
||||
@:privateAccess {
|
||||
FlxG.width = Std.int(oldSize.x);
|
||||
FlxG.height = Std.int(oldSize.y);
|
||||
|
||||
camera = FlxG.camera;
|
||||
cameras = FlxG.cameras.list;
|
||||
camerasDefault = FlxG.cameras.defaults;
|
||||
|
||||
FlxCamera._defaultCameras = FlxG.cameras.defaults = oldCamDefaults;
|
||||
FlxG.cameras.list = oldCamList;
|
||||
FlxG.camera = oldCam;
|
||||
|
||||
oldCamList = null;
|
||||
oldCam = null;
|
||||
|
||||
FlxG.game._state = oldState;
|
||||
|
||||
FlxG.bitmap = oldFrontEnd;
|
||||
oldFrontEnd = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function update(elapsed:Float) {
|
||||
|
||||
}
|
||||
|
||||
public function draw() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override function __enterFrame(t:Float) {
|
||||
@:privateAccess {
|
||||
beforeStateShit();
|
||||
|
||||
FlxG.cameras.update(FlxG.elapsed);
|
||||
state.tryUpdate(FlxG.elapsed);
|
||||
|
||||
FlxG.cameras.lock();
|
||||
state.draw();
|
||||
|
||||
FlxG.cameras.render();
|
||||
FlxG.cameras.unlock();
|
||||
|
||||
afterStateShit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,12 +95,9 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
|
||||
public function getSpecificAsset(id:String, type:String, source:AssetSource = BOTH):Dynamic {
|
||||
try {
|
||||
MemoryUtil.askDisable();
|
||||
|
||||
if (!id.startsWith("assets/")) {
|
||||
var ass = getSpecificAsset('assets/$id', type, source);
|
||||
if (ass != null) {
|
||||
MemoryUtil.askEnable();
|
||||
return ass;
|
||||
}
|
||||
}
|
||||
@@ -109,15 +106,11 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
|
||||
var asset = e.getAsset(id, type);
|
||||
if (asset != null) {
|
||||
MemoryUtil.askEnable();
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
|
||||
MemoryUtil.askEnable();
|
||||
return null;
|
||||
} catch(e) {
|
||||
MemoryUtil.askEnable();
|
||||
throw e;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -189,6 +189,8 @@ class Conductor
|
||||
if (FlxG.sound.music == null)
|
||||
reset();
|
||||
}
|
||||
private static var __lastChange:BPMChangeEvent;
|
||||
private static var __updateBeat:Bool;
|
||||
private static function update() {
|
||||
if (FlxG.state != null && FlxG.state is MusicBeatState && cast(FlxG.state, MusicBeatState).cancelConductorUpdate) return;
|
||||
|
||||
@@ -198,28 +200,28 @@ class Conductor
|
||||
|
||||
if (bpm > 0) {
|
||||
// updates curbeat and stuff
|
||||
var lastChange:BPMChangeEvent = {
|
||||
__lastChange = {
|
||||
stepTime: 0,
|
||||
songTime: 0,
|
||||
bpm: 0
|
||||
}
|
||||
};
|
||||
for (change in Conductor.bpmChangeMap)
|
||||
{
|
||||
if (Conductor.songPosition >= change.songTime)
|
||||
lastChange = change;
|
||||
__lastChange = change;
|
||||
}
|
||||
|
||||
if (lastChange.bpm > 0 && bpm != lastChange.bpm) changeBPM(lastChange.bpm);
|
||||
if (__lastChange.bpm > 0 && bpm != __lastChange.bpm) changeBPM(__lastChange.bpm);
|
||||
|
||||
curStepFloat = lastChange.stepTime + ((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet);
|
||||
curStepFloat = __lastChange.stepTime + ((Conductor.songPosition - __lastChange.songTime) / Conductor.stepCrochet);
|
||||
curBeatFloat = curStepFloat / 4;
|
||||
|
||||
if (curStep != (curStep = Std.int(curStepFloat))) {
|
||||
// updates step
|
||||
var updateBeat = curBeat != (curBeat = Std.int(curBeatFloat));
|
||||
var __updateBeat = curBeat != (curBeat = Std.int(curBeatFloat));
|
||||
|
||||
onStepHit.dispatch(curStep);
|
||||
if (updateBeat)
|
||||
if (__updateBeat)
|
||||
onBeatHit.dispatch(curBeat);
|
||||
|
||||
if (FlxG.state is IBeatReceiver) {
|
||||
@@ -228,7 +230,7 @@ class Conductor
|
||||
if (state is IBeatReceiver && (state.subState == null || state.subState.persistentUpdate)) {
|
||||
var st = cast(state, IBeatReceiver);
|
||||
st.stepHit(curStep);
|
||||
if (updateBeat)
|
||||
if (__updateBeat)
|
||||
st.beatHit(curBeat);
|
||||
}
|
||||
state = state.subState;
|
||||
|
||||
@@ -150,9 +150,6 @@ class Main extends Sprite
|
||||
ModsFolder.init();
|
||||
DesktopMain.init();
|
||||
DiscordUtil.init();
|
||||
#if ALLOW_MULTITASKING
|
||||
funkin.multitasking.MultiTaskingHandler.init();
|
||||
#end
|
||||
#if GLOBAL_SCRIPT
|
||||
funkin.scripting.GlobalScript.init();
|
||||
#end
|
||||
@@ -242,6 +239,14 @@ class Main extends Sprite
|
||||
// manual asset clearing since base openfl one doesnt clear lime one
|
||||
// doesnt clear bitmaps since flixel fork does it auto
|
||||
|
||||
@:privateAccess {
|
||||
// clear uint8 pools since it causes memory leak with openfl textfield
|
||||
for(length=>pool in openfl.display3D.utils.UInt8Buff._pools) {
|
||||
for(b in pool.clear())
|
||||
b.destroy();
|
||||
}
|
||||
openfl.display3D.utils.UInt8Buff._pools.clear();
|
||||
}
|
||||
scaleMode.resetSize();
|
||||
|
||||
var cache = cast(Assets.cache, AssetCache);
|
||||
@@ -252,7 +257,6 @@ class Main extends Sprite
|
||||
|
||||
Paths.assetsTree.clearCache();
|
||||
|
||||
MemoryUtil.clearMinor();
|
||||
MemoryUtil.clearMajor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,6 @@ import funkin.options.PlayerSettings;
|
||||
|
||||
class MusicBeatState extends FlxUIState implements IBeatReceiver
|
||||
{
|
||||
#if ALLOW_MULTITASKING
|
||||
public var parentWindow:funkin.multitasking.StateWindow;
|
||||
#end
|
||||
private var lastBeat:Float = 0;
|
||||
private var lastStep:Float = 0;
|
||||
|
||||
@@ -203,9 +200,7 @@ class MusicBeatState extends FlxUIState implements IBeatReceiver
|
||||
}
|
||||
|
||||
public override function destroy() {
|
||||
if (parentWindow == null)
|
||||
super.destroy();
|
||||
|
||||
super.destroy();
|
||||
call("onDestroy");
|
||||
if (stateScript != null)
|
||||
stateScript.destroy();
|
||||
|
||||
@@ -10,6 +10,7 @@ class AssetTreeInfo extends FramerateCategory {
|
||||
}
|
||||
|
||||
public override function __enterFrame(t:Int) {
|
||||
if (alpha <= 0.05) return;
|
||||
var text = 'Not initialized yet\n';
|
||||
if (Paths.assetsTree != null){
|
||||
text = "";
|
||||
|
||||
@@ -8,13 +8,14 @@ class ConductorInfo extends FramerateCategory {
|
||||
}
|
||||
|
||||
public override function __enterFrame(t:Int) {
|
||||
var text = 'Current Song Position: ${Conductor.songPosition}';
|
||||
text += '\n - ${Conductor.curBeat} beats';
|
||||
text += '\n - ${Conductor.curStep} steps';
|
||||
text += '\nCurrent BPM: ${Conductor.bpm}';
|
||||
text += '\nCurrent speed: ${FlxMath.roundDecimal(Conductor.speed, 2)}x';
|
||||
if (alpha <= 0.05) return;
|
||||
_text = 'Current Song Position: ${Conductor.songPosition}';
|
||||
_text += '\n - ${Conductor.curBeat} beats';
|
||||
_text += '\n - ${Conductor.curStep} steps';
|
||||
_text += '\nCurrent BPM: ${Conductor.bpm}';
|
||||
_text += '\nCurrent speed: ${FlxMath.roundDecimal(Conductor.speed, 2)}x';
|
||||
|
||||
this.text.text = text;
|
||||
this.text.text = _text;
|
||||
super.__enterFrame(t);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ class FramerateCategory extends Sprite {
|
||||
|
||||
public var bgSprite:Sprite;
|
||||
|
||||
private var _text:String = "";
|
||||
|
||||
public function new(title:String, text:String = "") {
|
||||
super();
|
||||
|
||||
@@ -41,6 +43,7 @@ class FramerateCategory extends Sprite {
|
||||
}
|
||||
|
||||
public override function __enterFrame(t:Int) {
|
||||
if (alpha <= 0.05) return;
|
||||
super.__enterFrame(t);
|
||||
|
||||
var width = Math.max(this.title.width, this.text.width) + (Framerate.instance.x * 2);
|
||||
|
||||
@@ -28,6 +28,7 @@ class FramerateCounter extends Sprite {
|
||||
}
|
||||
|
||||
public override function __enterFrame(t:Int) {
|
||||
if (alpha <= 0.05) return;
|
||||
super.__enterFrame(t);
|
||||
|
||||
lastFPS = CoolUtil.fpsLerp(lastFPS, FlxG.elapsed == 0 ? 0 : (1 / FlxG.elapsed), 0.25);
|
||||
|
||||
@@ -31,6 +31,7 @@ class MemoryCounter extends Sprite {
|
||||
}
|
||||
|
||||
public override function __enterFrame(t:Int) {
|
||||
if (alpha <= 0.05) return;
|
||||
super.__enterFrame(t);
|
||||
|
||||
memory = MemoryUtil.currentMemUsage();
|
||||
|
||||
@@ -10,11 +10,12 @@ class StatsInfo extends FramerateCategory {
|
||||
}
|
||||
|
||||
public override function __enterFrame(t:Int) {
|
||||
var text = "totalDC: " + Context3DStats.totalDrawCalls();
|
||||
text += "\nstageDC: " + Context3DStats.contextDrawCalls(DrawCallContext.STAGE);
|
||||
text += "\nstage3DDC: " + Context3DStats.contextDrawCalls(DrawCallContext.STAGE3D);
|
||||
if (alpha <= 0.05) return;
|
||||
_text = "totalDC: " + Context3DStats.totalDrawCalls();
|
||||
_text += "\nstageDC: " + Context3DStats.contextDrawCalls(DrawCallContext.STAGE);
|
||||
_text += "\nstage3DDC: " + Context3DStats.contextDrawCalls(DrawCallContext.STAGE3D);
|
||||
|
||||
this.text.text = text;
|
||||
this.text.text = _text;
|
||||
super.__enterFrame(t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,13 @@ class SystemInfo extends FramerateCategory {
|
||||
}
|
||||
|
||||
public override function __enterFrame(t:Int) {
|
||||
var text = 'System: ${lime.system.System.platformLabel} ${lime.system.System.platformVersion}';
|
||||
text += '\nObjs in state: ${FlxG.state.members.length}';
|
||||
text += '\nNb cameras: ${FlxG.cameras.list.length}';
|
||||
text += '\nCurrent state: ${Type.getClassName(Type.getClass(FlxG.state))}';
|
||||
if (alpha <= 0.05) return;
|
||||
_text = 'System: ${lime.system.System.platformLabel} ${lime.system.System.platformVersion}';
|
||||
_text += '\nObjs in state: ${FlxG.state.members.length}';
|
||||
_text += '\nNb cameras: ${FlxG.cameras.list.length}';
|
||||
_text += '\nCurrent state: ${Type.getClassName(Type.getClass(FlxG.state))}';
|
||||
|
||||
this.text.text = text;
|
||||
this.text.text = _text;
|
||||
super.__enterFrame(t);
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,8 @@ class MemoryUtil {
|
||||
enable();
|
||||
}
|
||||
|
||||
public static function init() {
|
||||
#if cpp
|
||||
#end
|
||||
}
|
||||
public static function init() {}
|
||||
|
||||
public static function clearMinor() {
|
||||
#if (cpp || java || neko)
|
||||
Gc.run(false);
|
||||
|
||||
Reference in New Issue
Block a user