Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Commit

Permalink
More exception loggers, and focus the output log tab on exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltris committed Jun 10, 2019
1 parent 5fd1c87 commit 95c0135
Show file tree
Hide file tree
Showing 20 changed files with 377 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ public class OnControllerConnectionChangeHandler : NativeMulticastDelegate<Nativ
public delegate void Signature(csbool connected, int userId, int controllerIndex);
private void NativeCallback(csbool connected, int userId, int controllerIndex)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
evnt(connected, userId, controllerIndex);
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(connected, userId, controllerIndex);
}
}
catch (Exception e)
{
FMessage.LogDelegateException(e);
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions Managed/UnrealEngine.Runtime/UnrealEngine.Runtime/Core/FMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,48 @@ public static void Crash(string message)
Native_FMessageDialog.Log(ref messageUnsafe.Array, ref categoryUnsafe.Array, ELogVerbosity.Fatal);
}
}

internal static void LogException(string exceptionMessage)
{
Log(ELogVerbosity.Error, "Unhandled exception: " + exceptionMessage);
FocusOutputLogTab();
}

internal static void LogException(Exception e, string message = null)
{
string additionalInfo = !string.IsNullOrEmpty(message) ? " (" + message + ")" : string.Empty;
Log(ELogVerbosity.Error, "Unhandled exception" + additionalInfo +": " + e);
FocusOutputLogTab();
}

internal static void LogDelegateException(Exception e)
{
LogException(e, "native delegate callback");
FocusOutputLogTab();
}

private static bool disableExceptionNotifier;
private static DateTime lastFocusOutputLogTab;
private static TimeSpan focusOutputLogTabDelay = TimeSpan.FromSeconds(20);
private static void FocusOutputLogTab()
{
if (disableExceptionNotifier)
{
return;
}

// Add a delay between each tab focus to avoid sitations where the user can't get way from the tab.
if (lastFocusOutputLogTab < DateTime.Now - focusOutputLogTabDelay)
{
lastFocusOutputLogTab = DateTime.Now;
Native_FMessageDialog.FocusOutputLogTab();
}
}

internal static void OnNativeFunctionsRegistered()
{
disableExceptionNotifier = Native_USharpSettings.Get_bDisableExceptionNotifier();
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,17 @@ public class ModulesChangedHandler : NativeMulticastDelegate<Native_FModuleManag
public delegate void Signature(FName moduleName, EModuleChangeReason reason);
private void NativeCallback(ref FName moduleName, EModuleChangeReason reason)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
evnt(moduleName, reason);
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(moduleName, reason);
}
}
catch (Exception e)
{
FMessage.LogDelegateException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ public class OnObjectModifiedHandler : NativeMulticastDelegate<Native_FCoreUObje
public delegate void Signature(UObject objectBeingModified);
private void NativeCallback(IntPtr objectBeingModified)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
evnt(GCHelper.Find(objectBeingModified));
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(GCHelper.Find(objectBeingModified));
}
}
catch (Exception e)
{
FMessage.LogDelegateException(e);
}
}
}
Expand All @@ -44,10 +51,17 @@ public class OnAssetLoadedHandler : NativeMulticastDelegate<Native_FCoreUObjectD
public delegate void Signature(UObject asset);
private void NativeCallback(IntPtr asset)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
evnt(GCHelper.Find(asset));
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(GCHelper.Find(asset));
}
}
catch (Exception e)
{
FMessage.LogDelegateException(e);
}
}
}
Expand All @@ -62,10 +76,17 @@ public class OnObjectSavedHandler : NativeMulticastDelegate<Native_FCoreUObjectD
public delegate void Signature(UObject savedObject);
private void NativeCallback(IntPtr savedObject)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(GCHelper.Find(savedObject));
}
}
catch (Exception e)
{
evnt(GCHelper.Find(savedObject));
FMessage.LogDelegateException(e);
}
}
}
Expand All @@ -79,11 +100,18 @@ public class PreLoadMapHandler : NativeMulticastDelegate<Native_FCoreUObjectDele
public delegate void Signature(string mapName);
private void NativeCallback(ref FScriptArray mapName)
{
string mapNameStr = FStringMarshaler.FromArray(mapName, false);
var evnt = managed.Delegate;
if (evnt != null)
try
{
string mapNameStr = FStringMarshaler.FromArray(mapName, false);
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(mapNameStr);
}
}
catch (Exception e)
{
evnt(mapNameStr);
FMessage.LogDelegateException(e);
}
}
}
Expand All @@ -97,10 +125,17 @@ public class PostLoadMapWithWorldHandler : NativeMulticastDelegate<Native_FCoreU
public delegate void Signature(UObject loadedWorld);
private void NativeCallback(IntPtr loadedWorld)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(GCHelper.Find(loadedWorld));
}
}
catch (Exception e)
{
evnt(GCHelper.Find(loadedWorld));
FMessage.LogDelegateException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ public class OnPostWorldCreationHandler : NativeMulticastDelegate<Native_FWorldD
public delegate void Signature(IntPtr world);
private void NativeCallback(IntPtr world)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
evnt(world);
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(world);
}
}
catch (Exception e)
{
FMessage.LogDelegateException(e);
}
}
}
Expand All @@ -45,10 +52,17 @@ public class OnPreWorldInitializationHandler : NativeMulticastDelegate<Native_FW
public delegate void Signature(IntPtr world, IntPtr ivs);
private void NativeCallback(IntPtr world, IntPtr ivs)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(world, ivs);
}
}
catch (Exception e)
{
evnt(world, ivs);
FMessage.LogDelegateException(e);
}
}
}
Expand All @@ -62,10 +76,17 @@ public class OnPostWorldInitializationHandler : NativeMulticastDelegate<Native_F
public delegate void Signature(IntPtr world, IntPtr ivs);
private void NativeCallback(IntPtr world, IntPtr ivs)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
evnt(world, ivs);
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(world, ivs);
}
}
catch (Exception e)
{
FMessage.LogDelegateException(e);
}
}
}
Expand All @@ -79,10 +100,17 @@ public class OnPostDuplicateHandler : NativeMulticastDelegate<Native_FWorldDeleg
public delegate void Signature(IntPtr world, bool duplicateForPIE, IntPtr replacementMap, IntPtr objectsToFixReferences);
private void NativeCallback(IntPtr world, csbool duplicateForPIE, IntPtr replacementMap, IntPtr objectsToFixReferences)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(world, duplicateForPIE, replacementMap, objectsToFixReferences);
}
}
catch (Exception e)
{
evnt(world, duplicateForPIE, replacementMap, objectsToFixReferences);
FMessage.LogDelegateException(e);
}
}
}
Expand All @@ -96,10 +124,17 @@ public class OnWorldCleanupHandler : NativeMulticastDelegate<Native_FWorldDelega
public delegate void Signature(IntPtr world, bool sessionEnded, bool cleanupResources);
private void NativeCallback(IntPtr world, csbool sessionEnded, csbool cleanupResources)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(world, sessionEnded, cleanupResources);
}
}
catch (Exception e)
{
evnt(world, sessionEnded, cleanupResources);
FMessage.LogDelegateException(e);
}
}
}
Expand All @@ -113,10 +148,17 @@ public class OnPostWorldCleanupHandler : NativeMulticastDelegate<Native_FWorldDe
public delegate void Signature(IntPtr world, bool sessionEnded, bool cleanupResources);
private void NativeCallback(IntPtr world, csbool sessionEnded, csbool cleanupResources)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
evnt(world, sessionEnded, cleanupResources);
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(world, sessionEnded, cleanupResources);
}
}
catch (Exception e)
{
FMessage.LogDelegateException(e);
}
}
}
Expand All @@ -131,10 +173,17 @@ public class OnPreWorldFinishDestroyHandler : NativeMulticastDelegate<Native_FWo
public delegate void Signature(IntPtr world);
private void NativeCallback(IntPtr world)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(world);
}
}
catch (Exception e)
{
evnt(world);
FMessage.LogDelegateException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ public class OnWorldAddedHandler : NativeMulticastDelegate<Native_UEngineDelegat
public delegate void Signature(IntPtr world);
private void NativeCallback(IntPtr world)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
evnt(world);
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(world);
}
}
catch (Exception e)
{
FMessage.LogDelegateException(e);
}
}
}
Expand All @@ -48,10 +55,17 @@ public class OnWorldDestroyedHandler : NativeMulticastDelegate<Native_UEngineDel
public delegate void Signature(IntPtr world);
private void NativeCallback(IntPtr world)
{
var evnt = managed.Delegate;
if (evnt != null)
try
{
var evnt = managed.Delegate;
if (evnt != null)
{
evnt(world);
}
}
catch (Exception e)
{
evnt(world);
FMessage.LogDelegateException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private static void ClassConstructor(ManagedClass managedClass, IntPtr objectIni
FMessage.OpenDialog(error);
lastInitializerException = DateTime.Now;
}
FMessage.Log(ELogVerbosity.Error, error);
FMessage.LogException(error);
}
}
}
Expand Down
Loading

0 comments on commit 95c0135

Please sign in to comment.