Skip to content

Commit

Permalink
Merge pull request #94 from nowsprinting/fix/terminates
Browse files Browse the repository at this point in the history
Fix terminate process and player build failure
  • Loading branch information
asurato authored Nov 5, 2024
2 parents e087479 + 808e9db commit b33861f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Editor/Commandline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private static void OnChangePlayModeState(PlayModeStateChange playModeStateChang
// Exit Unity when returning from play mode to edit mode.
// Because it may freeze when exiting without going through edit mode.
var exitCode = (int)AutopilotState.Instance.exitCode;
Debug.Log($"Exit Unity-editor by autopilot, exit code={exitCode}");
Debug.Log($"Exit Unity-editor by autopilot, exit code: {(int)exitCode}");
EditorApplication.Exit(exitCode);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Autopilot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ public async UniTask TerminateAsync(ExitCode exitCode, string message = null, st
JUnitReporter.Output(_state.settings.junitReportPath, (int)exitCode, message, stackTrace, time);
}

DestroyImmediate(this.gameObject);
Destroy(this.gameObject);

_logger.Log("Terminate Autopilot");
await Launcher.TeardownLaunchAutopilotAsync(_state, _logger, exitCode, "Autopilot", token);
Launcher.TeardownLaunchAutopilotAsync(_state, _logger, exitCode, "Autopilot").Forget();
}

[Obsolete("Use " + nameof(TerminateAsync))]
Expand Down
12 changes: 6 additions & 6 deletions Runtime/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
using DeNA.Anjin.Attributes;
using DeNA.Anjin.Settings;
using DeNA.Anjin.Utilities;
using NUnit.Framework;
using UnityEngine;
using Assert = UnityEngine.Assertions.Assert;
using Object = UnityEngine.Object;
#if UNITY_INCLUDE_TESTS
using NUnit.Framework;
Expand Down Expand Up @@ -220,8 +220,8 @@ private static Dictionary<int, List<MethodInfo>> GetOrderedInitializeOnLaunchAut
#endif
}

internal static async UniTask TeardownLaunchAutopilotAsync(AutopilotState state, ILogger logger,
ExitCode exitCode, string caller, CancellationToken token = default)
internal static async UniTaskVoid TeardownLaunchAutopilotAsync(AutopilotState state, ILogger logger,
ExitCode exitCode, string caller)
{
state.settings = null;
state.exitCode = exitCode;
Expand All @@ -232,7 +232,7 @@ internal static async UniTask TeardownLaunchAutopilotAsync(AutopilotState state,
// Play mode tests
if (TestContext.CurrentContext != null && exitCode != ExitCode.Normally)
{
throw new AssertionException($"{caller} failed with exit code {exitCode}");
throw new AssertionException($"{caller} failed with exit code {(int)exitCode}");
}
#endif
return; // Only terminate autopilot run if starting from play mode.
Expand All @@ -245,7 +245,7 @@ internal static async UniTask TeardownLaunchAutopilotAsync(AutopilotState state,

// XXX: Avoid a problem that Editor stay playing despite isPlaying get assigned false.
// SEE: https://github.com/DeNA/Anjin/issues/20
await UniTask.NextFrame(token);
await UniTask.NextFrame();
#if UNITY_EDITOR
EditorApplication.isPlaying = false;
// Note: If launched from the command line, `DeNA.Anjin.Editor.Commandline.OnChangePlayModeState()` will be called, and the Unity editor will be terminated.
Expand All @@ -254,7 +254,7 @@ internal static async UniTask TeardownLaunchAutopilotAsync(AutopilotState state,
else
{
// Player build launch from commandline
logger.Log($"Exit Unity-player by {caller}, exit code={exitCode}");
logger.Log($"Exit Unity-player by {caller}, exit code: {(int)exitCode}");
Application.Quit((int)exitCode);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Settings/AutopilotSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using DeNA.Anjin.Attributes;
using DeNA.Anjin.Loggers;
using DeNA.Anjin.Reporters;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Assertions;

namespace DeNA.Anjin.Settings
{
Expand Down Expand Up @@ -241,7 +241,7 @@ internal void OverrideByCommandLineArguments(Arguments args)
private static void Initialize()
{
var settings = AutopilotState.Instance.settings;
Assert.NotNull(settings);
Assert.IsNotNull(settings);

settings.ConvertLoggersFromObsoleteLogger(); // Note: before create default logger.
settings.CreateDefaultLoggerIfNeeded();
Expand Down

0 comments on commit b33861f

Please sign in to comment.