From 6f5c3a043f87152c813ea0915629c7224cd67e01 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Wed, 10 Apr 2024 14:45:07 -0400 Subject: [PATCH] Fix crash caused when game tries to render disposed sprites during a Sticker transition. --- source/funkin/graphics/FunkinCamera.hx | 6 +++++- source/funkin/play/PlayState.hx | 2 +- .../funkin/ui/debug/charting/ChartEditorState.hx | 4 ++-- source/funkin/ui/freeplay/FreeplayState.hx | 2 +- source/funkin/ui/mainmenu/MainMenuState.hx | 2 +- source/funkin/ui/options/ControlsMenu.hx | 2 +- source/funkin/ui/options/PreferencesMenu.hx | 2 +- source/funkin/ui/transition/StickerSubState.hx | 14 +++++++++----- 8 files changed, 21 insertions(+), 13 deletions(-) diff --git a/source/funkin/graphics/FunkinCamera.hx b/source/funkin/graphics/FunkinCamera.hx index 90861c263..8c8a1c9a7 100644 --- a/source/funkin/graphics/FunkinCamera.hx +++ b/source/funkin/graphics/FunkinCamera.hx @@ -47,9 +47,13 @@ class FunkinCamera extends FlxCamera public var shouldDraw:Bool = true; - public function new(x:Int = 0, y:Int = 0, width:Int = 0, height:Int = 0, zoom:Float = 0) + // Used to identify the camera during debugging. + final id:String = 'unknown'; + + public function new(id:String = 'unknown', x:Int = 0, y:Int = 0, width:Int = 0, height:Int = 0, zoom:Float = 0) { super(x, y, width, height, zoom); + this.id = id; bgTexture = pickTexture(width, height); bgBitmap = FixedBitmapData.fromTexture(bgTexture); bgFrame = new FlxFrame(new FlxGraphic('', null)); diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 795f493e8..486eb742c 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -1467,7 +1467,7 @@ class PlayState extends MusicBeatSubState */ function initCameras():Void { - camGame = new FunkinCamera(); + camGame = new FunkinCamera('playStateCamGame'); camGame.bgColor = BACKGROUND_COLOR; // Show a pink background behind the stage. camHUD = new FlxCamera(); camHUD.bgColor.alpha = 0; // Show the game scene behind the camera. diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index dba1a7e55..78222570a 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -2091,7 +2091,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState loadPreferences(); - uiCamera = new FunkinCamera(); + uiCamera = new FunkinCamera('chartEditorUI'); FlxG.cameras.reset(uiCamera); buildDefaultSongData(); @@ -5382,7 +5382,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState // Kill and replace the UI camera so it doesn't get destroyed during the state transition. uiCamera.kill(); FlxG.cameras.remove(uiCamera, false); - FlxG.cameras.reset(new FunkinCamera()); + FlxG.cameras.reset(new FunkinCamera('chartEditorUI2')); this.persistentUpdate = false; this.persistentDraw = false; diff --git a/source/funkin/ui/freeplay/FreeplayState.hx b/source/funkin/ui/freeplay/FreeplayState.hx index dc1f164ea..6fdc7e309 100644 --- a/source/funkin/ui/freeplay/FreeplayState.hx +++ b/source/funkin/ui/freeplay/FreeplayState.hx @@ -513,7 +513,7 @@ class FreeplayState extends MusicBeatSubState // var swag:Alphabet = new Alphabet(1, 0, 'swag'); - var funnyCam:FunkinCamera = new FunkinCamera(0, 0, FlxG.width, FlxG.height); + var funnyCam:FunkinCamera = new FunkinCamera('freeplayFunny', 0, 0, FlxG.width, FlxG.height); funnyCam.bgColor = FlxColor.TRANSPARENT; FlxG.cameras.add(funnyCam); diff --git a/source/funkin/ui/mainmenu/MainMenuState.hx b/source/funkin/ui/mainmenu/MainMenuState.hx index ecd67b4da..0e444782c 100644 --- a/source/funkin/ui/mainmenu/MainMenuState.hx +++ b/source/funkin/ui/mainmenu/MainMenuState.hx @@ -172,7 +172,7 @@ class MainMenuState extends MusicBeatState function resetCamStuff() { - FlxG.cameras.reset(new FunkinCamera()); + FlxG.cameras.reset(new FunkinCamera('mainMenu')); FlxG.camera.follow(camFollow, null, 0.06); FlxG.camera.snapToTarget(); } diff --git a/source/funkin/ui/options/ControlsMenu.hx b/source/funkin/ui/options/ControlsMenu.hx index 62ae4b1a9..dd7d5ff38 100644 --- a/source/funkin/ui/options/ControlsMenu.hx +++ b/source/funkin/ui/options/ControlsMenu.hx @@ -48,7 +48,7 @@ class ControlsMenu extends funkin.ui.options.OptionsState.Page { super(); - menuCamera = new FunkinCamera(); + menuCamera = new FunkinCamera('controlsMenu'); FlxG.cameras.add(menuCamera, false); menuCamera.bgColor = 0x0; camera = menuCamera; diff --git a/source/funkin/ui/options/PreferencesMenu.hx b/source/funkin/ui/options/PreferencesMenu.hx index c23c3f165..783aef0ba 100644 --- a/source/funkin/ui/options/PreferencesMenu.hx +++ b/source/funkin/ui/options/PreferencesMenu.hx @@ -21,7 +21,7 @@ class PreferencesMenu extends Page { super(); - menuCamera = new FunkinCamera(); + menuCamera = new FunkinCamera('prefMenu'); FlxG.cameras.add(menuCamera, false); menuCamera.bgColor = 0x0; camera = menuCamera; diff --git a/source/funkin/ui/transition/StickerSubState.hx b/source/funkin/ui/transition/StickerSubState.hx index 0b5e16f97..e5abef872 100644 --- a/source/funkin/ui/transition/StickerSubState.hx +++ b/source/funkin/ui/transition/StickerSubState.hx @@ -247,10 +247,6 @@ class StickerSubState extends MusicBeatSubState FlxTransitionableState.skipNextTransIn = true; FlxTransitionableState.skipNextTransOut = true; - // TODO: Rework this asset caching stuff - FunkinSprite.preparePurgeCache(); - FunkinSprite.purgeCache(); - // I think this grabs the screen and puts it under the stickers? // Leaving this commented out rather than stripping it out because it's cool... /* @@ -265,7 +261,15 @@ class StickerSubState extends MusicBeatSubState // FlxG.addChildBelowMouse(dipshit); */ - FlxG.switchState(() -> targetState(this)); + FlxG.switchState(() -> { + // TODO: Rework this asset caching stuff + // NOTE: This has to come AFTER the state switch, + // otherwise the game tries to render destroyed sprites! + FunkinSprite.preparePurgeCache(); + FunkinSprite.purgeCache(); + + return targetState(this); + }); } }); });