Skip to content

Commit 3b93872

Browse files
author
Stewart Miles
committed
Changed BuildTargetChecker to use RunOnMainThread.
Also, fixed use of Unity methods from a static constructor. This *may* have been contributing to a hang when the version handler plugin starts up. Bug: 131100117 Change-Id: I6dc4c2252b470520275b3e1763bb006ab3869f44
1 parent 6a1acdd commit 3b93872

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

source/VersionHandlerImpl/src/VersionHandlerImpl.cs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,39 +1981,25 @@ internal static string[] OnWillSaveAssets(string[] paths) {
19811981
/// </summary>
19821982
[InitializeOnLoad]
19831983
internal class BuildTargetChecker {
1984+
private const double POLL_INTERVAL_MILLISECONDS = 1000.0f;
19841985
private static BuildTarget? lastKnownBuildTarget = null;
1985-
private static int ticksSinceLastCheck = 0;
1986-
private static int ticksBetweenChecks = 60;
1987-
19881986

19891987
static BuildTargetChecker() {
1990-
HandleSettingsChanged();
1988+
RunOnMainThread.Run(HandleSettingsChanged, runNow: false);
19911989
}
19921990

1993-
public static void HandleSettingsChanged() {
1994-
RunOnMainThread.OnUpdate -= CheckBuildTarget;
1995-
if (Enabled && RenameToDisableFilesEnabled) {
1996-
RunOnMainThread.OnUpdate += CheckBuildTarget;
1997-
}
1998-
}
1991+
// NOTE: This should only be called from the main thread.
1992+
public static void HandleSettingsChanged() { CheckBuildTarget(); }
19991993

20001994
private static void CheckBuildTarget() {
2001-
ticksSinceLastCheck++;
2002-
if (ticksSinceLastCheck < ticksBetweenChecks) {
2003-
return;
2004-
}
2005-
2006-
if (!Enabled || !RenameToDisableFilesEnabled) {
2007-
RunOnMainThread.OnUpdate -= CheckBuildTarget;
2008-
}
2009-
20101995
var newBuildTarget = EditorUserBuildSettings.activeBuildTarget;
20111996
if (lastKnownBuildTarget == null || newBuildTarget != lastKnownBuildTarget) {
20121997
lastKnownBuildTarget = newBuildTarget;
20131998
HandleBuildTargetChanged(newBuildTarget);
20141999
}
2015-
2016-
ticksSinceLastCheck = 0;
2000+
if (Enabled && RenameToDisableFilesEnabled && !ExecutionEnvironment.InBatchMode) {
2001+
RunOnMainThread.Schedule(CheckBuildTarget, POLL_INTERVAL_MILLISECONDS);
2002+
}
20172003
}
20182004

20192005
private static void HandleBuildTargetChanged(BuildTarget newBuildTarget) {

source/VersionHandlerImpl/test/activation/Assets/PlayServicesResolver/Editor/TestEnabledCallback.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ private static bool SetInitialized() {
6969
/// Register a method to call when the Version Handler has enabled all plugins in the project.
7070
/// </summary>
7171
static TestEnabledCallback() {
72+
// Disable stack traces for more condensed logs.
73+
UnityEngine.Application.stackTraceLogType = UnityEngine.StackTraceLogType.None;
7274
UnityEngine.Debug.Log("Ensure plugin components are not loaded.");
7375
if (!SetInitialized()) {
7476
foreach (var kv in EntryPoints) {

0 commit comments

Comments
 (0)