From e4e516dd30595000b3953ed0ae87fe0a1ebc96f0 Mon Sep 17 00:00:00 2001
From: Eric Myllyoja <ericmyllyoja@gmail.com>
Date: Mon, 18 Apr 2022 20:09:02 -0400
Subject: [PATCH] Crash fix for Stress

---
 source/funkin/play/PlayState.hx   | 31 --------------------------
 source/funkin/play/stage/Stage.hx | 36 ++++++++++++++++++++-----------
 2 files changed, 24 insertions(+), 43 deletions(-)

diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx
index ce31dcbbe..a127e70b2 100644
--- a/source/funkin/play/PlayState.hx
+++ b/source/funkin/play/PlayState.hx
@@ -832,10 +832,6 @@ class PlayState extends MusicBeatState implements IHook
 				// swagNote.data = songNotes;
 				swagNote.data.sustainLength = songNotes.sustainLength;
 				swagNote.data.altNote = songNotes.altNote;
-<<<<<<< HEAD
-=======
-
->>>>>>> origin/master
 				swagNote.scrollFactor.set(0, 0);
 
 				var susLength:Float = swagNote.data.sustainLength;
@@ -941,11 +937,7 @@ class PlayState extends MusicBeatState implements IHook
 			regenNoteData(); // loads the note data from start
 			health = 1;
 			songScore = 0;
-<<<<<<< HEAD
 			Countdown.performCountdown(currentStageId.startsWith('school'));
-=======
-			restartCountdownTimer();
->>>>>>> origin/master
 
 			needsReset = false;
 		}
@@ -1261,19 +1253,11 @@ class PlayState extends MusicBeatState implements IHook
 					// TODO: Why the hell is the noteMiss logic in two different places?
 					if (daNote.tooLate)
 					{
-<<<<<<< HEAD
 						var event:NoteScriptEvent = new NoteScriptEvent(ScriptEvent.NOTE_MISS, daNote, true);
 						dispatchEvent(event);
-						health -= 0.0775;
-=======
-						if (curStage != null)
-						{
-							curStage.onNoteMiss(daNote);
-						}
 
 						// lose less health on sustain notes!
 						health -= 0.0775 * (daNote.isSustainNote ? 0.2 : 1); // if it's sustain, multiply it by 0.2 (not checked for balence yet), else keep it same (multiply by 1)
->>>>>>> origin/master
 						vocals.volume = 0;
 						killCombo();
 					}
@@ -1541,15 +1525,9 @@ class PlayState extends MusicBeatState implements IHook
 			switch (currentStageId)
 			{
 				case 'limo':
-<<<<<<< HEAD
 					cameraFollowPoint.x = currentStage.getBoyfriend().getMidpoint().x - 300;
 				case 'mall':
 					cameraFollowPoint.y = currentStage.getBoyfriend().getMidpoint().y - 200;
-=======
-					camFollow.x = boyfriend.getMidpoint().x - 300;
-				case 'mallXmas':
-					camFollow.y = boyfriend.getMidpoint().y - 200;
->>>>>>> origin/master
 				case 'school' | 'schoolEvil':
 					cameraFollowPoint.x = currentStage.getBoyfriend().getMidpoint().x - 200;
 					cameraFollowPoint.y = currentStage.getBoyfriend().getMidpoint().y - 200;
@@ -1742,17 +1720,8 @@ class PlayState extends MusicBeatState implements IHook
 		if (!super.stepHit())
 			return false;
 
-<<<<<<< HEAD
-		if (Math.abs(FlxG.sound.music.time - (Conductor.songPosition - Conductor.offset)) > 20
-			|| (currentSong.needsVoices && Math.abs(vocals.time - (Conductor.songPosition - Conductor.offset)) > 20))
-=======
-	override function stepHit()
-	{
-		super.stepHit();
-
 		if (Math.abs(FlxG.sound.music.time - (Conductor.songPosition - Conductor.offset)) > 20
 			|| Math.abs(vocals.checkSyncError(Conductor.songPosition - Conductor.offset)) > 20)
->>>>>>> origin/master
 		{
 			resyncVocals();
 		}
diff --git a/source/funkin/play/stage/Stage.hx b/source/funkin/play/stage/Stage.hx
index 8d77e374a..6a0cce769 100644
--- a/source/funkin/play/stage/Stage.hx
+++ b/source/funkin/play/stage/Stage.hx
@@ -321,33 +321,45 @@ class Stage extends FlxSpriteGroup implements IHook implements IPlayStateScripte
 
 		for (prop in this.namedProps)
 		{
-			remove(prop);
-			prop.kill();
-			prop.destroy();
+			if (prop != null)
+			{
+				remove(prop);
+				prop.kill();
+				prop.destroy();
+			}
 		}
 		namedProps.clear();
 
 		for (char in this.characters)
 		{
-			remove(char);
-			char.kill();
-			char.destroy();
+			if (char != null)
+			{
+				remove(char);
+				char.kill();
+				char.destroy();
+			}
 		}
 		characters.clear();
 
 		for (bopper in boppers)
 		{
-			remove(bopper);
-			bopper.kill();
-			bopper.destroy();
+			if (bopper != null)
+			{
+				remove(bopper);
+				bopper.kill();
+				bopper.destroy();
+			}
 		}
 		boppers = [];
 
 		for (sprite in this.group)
 		{
-			remove(sprite);
-			sprite.kill();
-			sprite.destroy();
+			if (sprite != null)
+			{
+				sprite.kill();
+				sprite.destroy();
+				remove(sprite);
+			}
 		}
 		group.clear();
 	}