Skip to content

Commit

Permalink
Partial crash dialogue implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sqirradotdev committed Sep 12, 2021
1 parent 716d00c commit 33280d0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Binary file added FE-CrashDialog.exe
Binary file not shown.
8 changes: 8 additions & 0 deletions Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<set name="BUILD_DIR" value="export" />
<source path="source" />
<assets path="assets" />
<assets path="FE-CrashDialog.exe" type="template" if="windows release" />
<!--<assets path="mods" />-->

<!-- _______________________________ Libraries ______________________________ -->
Expand All @@ -46,6 +47,9 @@

<!-- ______________________________ Haxedefines _____________________________ -->

<set name="BUILD_DIR" value="export/debug" if="debug" />
<set name="BUILD_DIR" value="export/release" unless="debug" />

<!--Enable the Flixel core recording system-->
<!--<haxedef name="FLX_RECORD" />-->

Expand Down Expand Up @@ -76,6 +80,10 @@
<!--Enable this for Nape release builds for a serious peformance improvement-->
<haxedef name="NAPE_RELEASE_BUILD" unless="debug" />

<!-- Akways enable Null Object Reference check for crash dialog -->
<haxedef name="HXCPP_CHECK_POINTER" if="release" />
<haxedef name="HXCPP_STACK_LINE" if="release" />

<!-- _________________________________ Custom _______________________________ -->

<icon path="art/icon16.png" size='16'/>
Expand Down
67 changes: 67 additions & 0 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ import flixel.util.FlxColor;
import gameFolder.meta.*;
import gameFolder.meta.data.PlayerSettings;
import gameFolder.meta.data.dependency.Discord;
import haxe.CallStack.StackItem;
import haxe.CallStack;
import haxe.io.Path;
import lime.app.Application;
import openfl.Assets;
import openfl.Lib;
import openfl.display.FPS;
import openfl.display.Sprite;
import openfl.events.Event;
import openfl.events.UncaughtErrorEvent;
import sys.FileSystem;
import sys.io.File;
import sys.io.Process;

// Here we actually import the states and metadata, and just the metadata.
// It's nice to have modularity so that we don't have ALL elements loaded at the same time.
Expand Down Expand Up @@ -137,6 +145,8 @@ class Main extends Sprite
note studders and shit its weird.
**/

Lib.current.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onCrash);

#if html5
framerate = 60;
#end
Expand Down Expand Up @@ -230,4 +240,61 @@ class Main extends Sprite
}
// */
}

function onCrash(e:UncaughtErrorEvent):Void
{
var errMsg:String = "";
var path:String;
var callStack:Array<StackItem> = CallStack.exceptionStack(true);
var dateNow:String = Date.now().toString();

dateNow = StringTools.replace(dateNow, " ", "_");
dateNow = StringTools.replace(dateNow, ":", "'");

path = "./crash/" + "FE_" + dateNow + ".txt";

for (stackItem in callStack)
{
switch (stackItem)
{
case FilePos(s, file, line, column):
errMsg += file + " (line " + line + ")\n";
default:
Sys.println(stackItem);
}
}

errMsg += "\nUncaught Error: " + e.error + "\nPlease report this error to the GitHub page: https://github.com/Yoshubs/Forever-Engine";

if (!FileSystem.exists("./crash/"))
FileSystem.createDirectory("./crash/");

File.saveContent(path, errMsg + "\n");

Sys.println(errMsg);
Sys.println("Crash dump saved in " + Path.normalize(path));

var crashDialoguePath:String = "FE-CrashDialog";

#if windows
crashDialoguePath += ".exe";
#end

if (FileSystem.exists("./" + crashDialoguePath))
{
Sys.println("Found crash dialog: " + crashDialoguePath);

#if linux
crashDialoguePath = "./" + crashDialoguePath;
#end
new Process(crashDialoguePath, [path]);
}
else
{
Sys.println("No crash dialog found! Making a simple alert instead...");
Application.current.window.alert(errMsg, "Error!");
}

Sys.exit(1);
}
}

0 comments on commit 33280d0

Please sign in to comment.