diff --git a/.vscode/settings.json b/.vscode/settings.json index 5eee2d85..1d26a96f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,10 @@ { "editor.detectIndentation": false, - "editor.insertSpaces": false + "editor.insertSpaces": false, + "files.associations": { + "*.hx": "haxe", + "*.hscript": "haxe", + "*.hsc": "haxe", + "*.hxs": "haxe" + } } \ No newline at end of file diff --git a/source/funkin/menus/PauseSubState.hx b/source/funkin/menus/PauseSubState.hx index e6ee4ce3..ab4963e1 100644 --- a/source/funkin/menus/PauseSubState.hx +++ b/source/funkin/menus/PauseSubState.hx @@ -49,10 +49,11 @@ class PauseSubState extends MusicBeatSubstate menuItems = event.options; - pauseMusic = new FlxSound().loadEmbedded(Paths.music(event.music), true, true); + pauseMusic = FlxG.sound.load(Paths.music(event.music)); pauseMusic.volume = 0; + pauseMusic.persist = false; + pauseMusic.group = FlxG.sound.defaultMusicGroup; pauseMusic.play(false, FlxG.random.int(0, Std.int(pauseMusic.length / 2))); - FlxG.sound.list.add(pauseMusic); if (__cancelDefault = event.cancelled) return; @@ -154,9 +155,13 @@ class PauseSubState extends MusicBeatSubstate if(FlxG.cameras.list.contains(camera)) FlxG.cameras.remove(camera, true); pauseScript.call("onDestroy"); - if (pauseMusic != null) pauseMusic.destroy(); pauseScript.destroy(); + if (pauseMusic != null) + @:privateAccess { + FlxG.sound.destroySound(pauseMusic); + } + super.destroy(); } diff --git a/source/funkin/scripting/HScript.hx b/source/funkin/scripting/HScript.hx index be4fbb66..96dfa607 100644 --- a/source/funkin/scripting/HScript.hx +++ b/source/funkin/scripting/HScript.hx @@ -1,11 +1,13 @@ package funkin.scripting; import hscript.Expr.Error; +import hscript.Parser; import openfl.Assets; import hscript.*; class HScript extends Script { public var interp:Interp; + public var parser:Parser; public var expr:Expr; public override function onCreate(path:String) { @@ -14,7 +16,7 @@ class HScript extends Script { interp = new Interp(); var code:String = Assets.getText(path); - var parser = new hscript.Parser(); + parser = new Parser(); parser.allowJSON = parser.allowMetadata = parser.allowTypes = true; parser.preprocesorValues = Script.getDefaultPreprocessors(); interp.errorHandler = _errorHandler; @@ -28,7 +30,8 @@ class HScript extends Script { })); try { - expr = parser.parseString(code, fileName); + if (code != null && code.trim() != "") + expr = parser.parseString(code, fileName); } catch(e:Error) { _errorHandler(e); } catch(e) { @@ -113,4 +116,70 @@ class HScript extends Script { public override function setPublicMap(map:Map) { this.interp.publicVariables = map; } + + public override function onDestroy() { + @:privateAccess { + // INTERP + if (interp != null) { + interp.scriptObject = null; + interp.errorHandler = null; + interp.variables.clear(); + interp.variables = null; + interp.publicVariables = null; + interp.staticVariables = null; + for(l in interp.locals) + if (l != null) + l.r = null; + interp.locals.clear(); + interp.locals = null; + interp.binops.clear(); + interp.binops = null; + interp.depth = 0; + interp.inTry = false; + while(interp.declared.length > 0) + interp.declared.shift(); + interp.declared = null; + interp.returnValue = null; + interp.isBypassAccessor = false; + interp.importEnabled = false; + interp.allowStaticVariables = false; + interp.allowPublicVariables = false; + while(interp.importBlocklist.length > 0) + interp.importBlocklist.shift(); + interp.importBlocklist = null; + while(interp.__instanceFields.length > 0) + interp.importBlocklist.shift(); + interp.__instanceFields = null; + interp.curExpr = null; + } + + if (parser != null) { + parser.line = 0; + parser.opChars = null; + parser.identChars = null; + parser.opPriority.clear(); + parser.opPriority = null; + parser.opRightAssoc.clear(); + parser.opRightAssoc = null; + parser.preprocesorValues.clear(); + parser.preprocesorValues = null; + parser.input = null; + parser.readPos = 0; + parser.char = 0; + parser.ops = null; + parser.idents = null; + parser.uid = 0; + parser.origin = null; + parser.tokenMin = 0; + parser.tokenMax = 0; + parser.oldTokenMin = 0; + parser.oldTokenMax = 0; + parser.tokens = null; + } + + expr = null; + parser = null; + interp = null; + } + } } \ No newline at end of file diff --git a/source/funkin/system/AssetsLibraryList.hx b/source/funkin/system/AssetsLibraryList.hx index a8be955e..8c9b5f0b 100644 --- a/source/funkin/system/AssetsLibraryList.hx +++ b/source/funkin/system/AssetsLibraryList.hx @@ -139,10 +139,14 @@ class AssetsLibraryList extends AssetLibrary { __defaultLibraries.push(base); } - public function reset() { + public function unloadLibraries() { for(l in libraries) if (!__defaultLibraries.contains(l)) l.unload(); + } + + public function reset() { + unloadLibraries(); libraries = []; diff --git a/source/funkin/system/Main.hx b/source/funkin/system/Main.hx index b9ece676..d6432c6e 100644 --- a/source/funkin/system/Main.hx +++ b/source/funkin/system/Main.hx @@ -245,6 +245,8 @@ class Main extends Sprite openfl.display3D.utils.UInt8Buff._pools.clear(); } + MemoryUtil.clearMinor(); MemoryUtil.clearMajor(); + MemoryUtil.clearMinor(); } }