Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix terminate process and player build failure #94

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Editor/Commandline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,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 @@ -217,8 +217,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 @@ -229,7 +229,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 @@ -242,7 +242,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 @@ -251,7 +251,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 @@ public 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