diff --git a/source/funkin/ui/title/TitleState.hx b/source/funkin/ui/title/TitleState.hx
index f9a0f7a0c..839992eea 100644
--- a/source/funkin/ui/title/TitleState.hx
+++ b/source/funkin/ui/title/TitleState.hx
@@ -271,7 +271,7 @@ class TitleState extends MusicBeatState
     #if desktop
     if (FlxG.keys.justPressed.ESCAPE)
     {
-      Sys.exit(0);
+      openfl.Lib.application.window.close();
     }
     #end
 
diff --git a/source/funkin/util/logging/CrashHandler.hx b/source/funkin/util/logging/CrashHandler.hx
index 1b607ddfd..4ec578173 100644
--- a/source/funkin/util/logging/CrashHandler.hx
+++ b/source/funkin/util/logging/CrashHandler.hx
@@ -61,6 +61,12 @@ class CrashHandler
     {
       trace('Error while handling crash: ' + e);
     }
+
+    #if sys
+    Sys.sleep(1); // wait a few moments of margin to process.
+    // Exit the game. Since it threw an error, we use a non-zero exit code.
+    openfl.Lib.application.window.close();
+    #end
   }
 
   static function onCriticalError(message:String):Void
@@ -83,8 +89,9 @@ class CrashHandler
     }
 
     #if sys
+    Sys.sleep(1); // wait a few moments of margin to process.
     // Exit the game. Since it threw an error, we use a non-zero exit code.
-    Sys.exit(1);
+    openfl.Lib.application.window.close();
     #end
   }