Skip to content

Commit

Permalink
fix crash on single-file app because of wrong assembly location
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobharder committed Oct 9, 2023
1 parent b0731e1 commit 95c3e61
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 15 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: main

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fetch-depth: 0

- name: Build
run: (cd source && dotnet build Burntime.MonoGl -c Release /p:DebugSymbols=false /p:PublishReadyToRun=false /p:TieredCompilation=false --self-contained /p:PublishSingleFile=true && cd ..)
run: (cd source && dotnet publish Burntime.MonoGl -c Release /p:DebugSymbols=false /p:PublishReadyToRun=false /p:TieredCompilation=false --self-contained /p:PublishSingleFile=true && cd ..)

- name: Package
run: |
Expand Down
22 changes: 11 additions & 11 deletions source/Burntime.Core/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@

public class Log
{
static StreamWriter file;
public static StreamWriter? File { get; private set; }
public static bool DebugOut;

public static string FormatPercentage(float factor) => System.Math.Round(factor * 100) + "%";
public static string FormatPercentage(Vector2f factor) => System.Math.Round(factor.x * 100) + "% x " + System.Math.Round(factor.y * 100) + "%";

static public void Initialize(String file)
{
Log.file = new StreamWriter(file, false);
Log.File = new StreamWriter(file, false);
}

static public void Info(String str)
{
if (file != null)
if (File != null)
{
file.WriteLine("[info] " + str);
file.Flush();
File.WriteLine("[info] " + str);
File.Flush();
}
}

static public void Warning(String str)
{
if (file != null)
if (File != null)
{
file.WriteLine("[warning] " + str);
file.Flush();
File.WriteLine("[warning] " + str);
File.Flush();
}
}

static public void Debug(String str)
{
if (file != null && DebugOut)
if (File != null && DebugOut)
{
file.WriteLine("[debug] " + str);
file.Flush();
File.WriteLine("[debug] " + str);
File.Flush();
}
}
}
5 changes: 4 additions & 1 deletion source/Burntime.MonoGl/BurntimeGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ public BurntimeGame()
protected override void Initialize()
{
Log.Initialize("log.txt");
Log.Info(System.DateTime.Now.ToLocalTime().ToString());
string version = FileVersionInfo.GetVersionInfo(System.IO.Path.Combine(System.AppContext.BaseDirectory, "burntime.exe")).ProductVersion ?? "?";
Log.Info("Burntime version " + version);

Window.Title = "Burntime " + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion ?? "?";
Window.Title = "Burntime " + version;

FileSystem.BasePath = "";
FileSystem.AddPackage("system", "system");
Expand Down
72 changes: 72 additions & 0 deletions source/Burntime.MonoGl/CustomExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
//using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace Burntime
{
//public class CustomExceptionHandler
//{
// public void OnThreadException(object sender, UnhandledExceptionEventArgs args)
// {
// Exception e = args.ExceptionObject as Exception;
// if (e == null)
// {
// MessageBox.Show("Error: Unknown", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
// }
// else
// {
// ErrorMsg.LogException(e);

// MessageBox.Show("Error: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
// }

// // close
// Environment.Exit(1);
// }
//};

static class ErrorMsg
{
//public static void ShowError(string msg)
//{
// MessageBox.Show("Error: " + msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
//}

//public static void ShowError(string msg, Exception e)
//{
// MessageBox.Show("Error: " + msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// LogException(e);
//}

// add exception to errorlog.txt
public static void LogException(Exception exception)
{
var log = (StreamWriter writer, Exception e) =>
{
writer.WriteLine();
writer.WriteLine("----------------------------------------------------------------------");
writer.WriteLine(System.DateTime.Now.ToLocalTime().ToString());
writer.WriteLine("exception: " + e.Message);
writer.WriteLine("trace:");
writer.Write(e.StackTrace);
writer.WriteLine();

writer.Flush();
writer.Close();
};

try
{
if (Platform.Log.File is not null)
log(Platform.Log.File, exception);
}
catch { }

using StreamWriter writer = new("crash.txt", true);
log(writer, exception);

#warning TODO message box?
}
}
}
18 changes: 18 additions & 0 deletions source/Burntime.MonoGl/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@

using Burntime;

#if (DEBUG)

using var game = new Burntime.MonoGl.BurntimeGame();
game.Run();

#else

try
{
using var game = new Burntime.MonoGl.BurntimeGame();
game.Run();
}
catch (System.Exception exception)
{
ErrorMsg.LogException(exception);
}

#endif

0 comments on commit 95c3e61

Please sign in to comment.