Skip to content
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
6 changes: 4 additions & 2 deletions AGXUnity/Sensor/LidarSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,10 @@ public bool Remove( LidarOutput output )
return false;

m_outputs.Remove( output );
if ( Native != null )
output.Disconnect();
if ( Native != null ) {
if ( output.Native.getParent() == Native )
output.Disconnect();
}
return true;
}

Expand Down
14 changes: 8 additions & 6 deletions AGXUnity/Sensor/SensorEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,19 +617,21 @@ internal void DisposeRT()
m_meshFilters.Clear();
m_explicitInclusions.Clear();

Native?.Dispose();
Native = null;
}

protected override void OnDestroy()
{
if ( Simulation.HasInstance ) {
Simulation.Instance.StepCallbacks.PostSynchronizeTransforms -= UpdateEnvironment;
Simulation.Instance.StepCallbacks.PreStepForward -= AddNew;
}

ScriptComponent.OnInitialized -= LateInitializeScriptComponent;

Native?.Dispose();
Native = null;
}

protected override void OnDestroy()
{
DisposeRT();

base.OnDestroy();
}
}
Expand Down
2 changes: 0 additions & 2 deletions AGXUnity/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ protected override void OnDestroy()
m_solverSettings.SetSimulation( null );
if ( SensorEnvironment.HasInstance )
SensorEnvironment.Instance.DisposeRT();
m_simulation.setSensorEnvironment( null );
m_simulation.cleanup();
}
m_simulation = null;
Expand All @@ -553,7 +552,6 @@ protected override void OnApplicationQuit()
if ( m_simulation != null ) {
if ( SensorEnvironment.HasInstance )
SensorEnvironment.Instance.DisposeRT();
m_simulation.setSensorEnvironment( null );
m_simulation.cleanup();
}
}
Expand Down
23 changes: 0 additions & 23 deletions Tests/Editor/DisableLoggingFixture.cs

This file was deleted.

1 change: 1 addition & 0 deletions Tests/Editor/SetupPlaymodeTestPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

[assembly: TestPlayerBuildModifier( typeof( SetupPlaymodeTestPlayer ) )]
[assembly: PostBuildCleanup( typeof( SetupPlaymodeTestPlayer ) )]
[assembly: TestMustExpectAllLogs]

public class SetupPlaymodeTestPlayer : ITestPlayerBuildModifier, IPostBuildCleanup
{
Expand Down
5 changes: 1 addition & 4 deletions Tests/Runtime/LidarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ public IEnumerator TestAddCableAfterInitialization()
var cableComp = cable.AddComponent<Cable>();
cableComp.Route.Add( Cable.NodeType.BodyFixedNode, cable, Vector3.right, Quaternion.Euler( 0, -90, 0 ) );
cableComp.Route.Add( Cable.NodeType.BodyFixedNode, cable, Vector3.left, Quaternion.Euler( 0, -90, 0 ) );
cable.AddComponent<CableRenderer>();

TestUtils.InitializeAll();

Expand All @@ -545,7 +544,6 @@ public IEnumerator TestRemoveCable()
var cableComp = cable.AddComponent<Cable>();
cableComp.Route.Add( Cable.NodeType.BodyFixedNode, cable, Vector3.right, Quaternion.Euler( 0, -90, 0 ) );
cableComp.Route.Add( Cable.NodeType.BodyFixedNode, cable, Vector3.left, Quaternion.Euler( 0, -90, 0 ) );
cable.AddComponent<CableRenderer>();

TestUtils.InitializeAll();

Expand Down Expand Up @@ -577,7 +575,6 @@ public IEnumerator TestDisableEnableCable()
var cableComp = cable.AddComponent<Cable>();
cableComp.Route.Add( Cable.NodeType.BodyFixedNode, cable, Vector3.right, Quaternion.Euler( 0, -90, 0 ) );
cableComp.Route.Add( Cable.NodeType.BodyFixedNode, cable, Vector3.left, Quaternion.Euler( 0, -90, 0 ) );
cable.AddComponent<CableRenderer>();

TestUtils.InitializeAll();
yield return TestUtils.Step();
Expand Down Expand Up @@ -1105,7 +1102,7 @@ public IEnumerator TestReadFromFileCsvLidar()
modelData.FirstLineIsHeader = false;
modelData.FrameSize = 2;
modelData.TwoColumns = false;
modelData.FilePath = "Assets/AGXUnity/Tests/Runtime/Test Resources/csv_lidar_pattern.csv";
modelData.FilePath = ResourceHelper.GetTestResource( "csv_lidar_pattern.csv" );

var output = new LidarOutput { agxSensor.RtOutput.Field.XYZ_VEC3_F32 };
lidarComp.Add( output );
Expand Down
6 changes: 3 additions & 3 deletions Tests/Runtime/OpenPLXTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public IEnumerator TestInvertedPendulum()
{
LoadOpenPLX( "inverted_pendulum.openplx" );
GameObject.Find( "inverted_pendulum" ).AddComponent<Aux.InvertedPendulumController>();
// Inverted pendulum is calibrated for 60hz
//Time.fixedDeltaTime = 1.0f/60.0f;

var cartRB = FindComponentByName<RigidBody>("inverted_pendulum/PendulumScene/cart");
var rodRB = FindComponentByName<RigidBody>("inverted_pendulum/PendulumScene/rod");

Expand All @@ -109,7 +108,6 @@ public IEnumerator TestInvertedPendulum()

Assert.AreEqual( 0.0f, cartRB.transform.position.x, 0.01f, "Cart Position" );
Assert.AreEqual( 0.0f, cartRB.LinearVelocity.x, 0.1f, "Cart Velocity" );
//Time.fixedDeltaTime = 1.0f/50.0f;
}

[UnityTest]
Expand Down Expand Up @@ -573,6 +571,8 @@ public IEnumerator TestSteering()
[UnityTest]
public IEnumerator TestShovelTerrainImport()
{
LogAssert.Expect( LogType.Warning, new Regex( @"AGXUnity\.Rendering\.DeformableTerrainParticleRenderer:.*" ) );

var root = LoadOpenPLX( "shovel.openplx" );
var shovelGO = root.FindMappedObject( "ShovelScene.shovel.shovel" );
Assert.NotNull( shovelGO );
Expand Down
47 changes: 47 additions & 0 deletions Tests/Runtime/ResourceHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Callbacks;
#endif

public static class ResourceHelper
{
private static string[] s_trackedResources =
{
"csv_lidar_pattern.csv"
};

private static string GetEditorResourcePath( [CallerFilePath] string path = "" ) => Path.Combine( Path.GetDirectoryName( path ), "Test Resources" );
private static string GetRuntimeResourcePath() => Path.Combine( Application.dataPath, "Test Resources" );
private static string ResourcePath => Application.isEditor ? GetEditorResourcePath() : GetRuntimeResourcePath();

#if UNITY_EDITOR
[PostProcessBuild( 16 )]
public static void OnPostProcessBuild( BuildTarget target, string targetPathFilename )
{
var targetExecutableFileInfo = new FileInfo( targetPathFilename );
var targetDataPath = targetExecutableFileInfo.Directory.FullName +
Path.DirectorySeparatorChar +
Path.GetFileNameWithoutExtension( targetExecutableFileInfo.Name ) +
"_Data";

targetDataPath = Path.Combine( targetDataPath, "Test Resources" );
Debug.Log( $"Copying test resources to '{targetDataPath}'" );

Directory.CreateDirectory( targetDataPath );

foreach ( var f in s_trackedResources )
File.Copy( Path.Combine( ResourcePath, f ), Path.Combine( targetDataPath, f ) );
}
#endif

public static string GetTestResource( string identifier )
{
Debug.Assert( s_trackedResources.Contains( identifier ), $"File '{identifier}' is not a tracked test resource" );

return Path.Combine( ResourcePath, identifier );
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Tests/Runtime/RuntimeFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using AGXUnity;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

[assembly: TestMustExpectAllLogs]

namespace AGXUnityTesting.Runtime
{
Expand All @@ -10,6 +13,10 @@ public class AGXUnityFixture
public void SetupSimulationInstance()
{
Simulation.Instance.GetInitialized();
Simulation.Instance.PreIntegratePositions = true;
Simulation.Instance.LogEnabled = true;
Simulation.Instance.AGXUnityLogLevel = LogLevel.Warning;
Simulation.Instance.LogToUnityConsole = true;
}

[OneTimeTearDown]
Expand Down
3 changes: 1 addition & 2 deletions Tests/Runtime/TerrainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public IEnumerator SetupTerrainScene()
[UnityTearDown]
public IEnumerator TearDownTerrainScene()
{
GameObject.Destroy( unityTerrain.gameObject );
yield return null;
yield return TestUtils.DestroyAndWait( unityTerrain.gameObject );
}

[Test]
Expand Down
16 changes: 8 additions & 8 deletions Tests/Runtime/VehicleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace AGXUnityTesting.Runtime
{
public class VehicleTests
public class VehicleTests : AGXUnityFixture
{
private GameObject CreateShape<T>( Vector3 transform = new Vector3() )
where T : Shape
Expand Down Expand Up @@ -74,13 +74,6 @@ private BasicVehicle CreateBasicVehicle( System.Func<RigidBody, RigidBody, int,
};
}

[OneTimeSetUp]
public void EnableLogging()
{
Simulation.Instance.LogToUnityConsole = true;
Simulation.Instance.AGXUnityLogLevel = LogLevel.Debug;
}

[UnityTearDown]
public IEnumerator CleanVehicleScene()
{
Expand All @@ -93,6 +86,8 @@ public IEnumerator CleanVehicleScene()
var toDelete = objects.Where(x => x is not Simulation).Select(x => x.gameObject).ToArray();

yield return TestUtils.DestroyAndWait( toDelete );

yield return TestUtils.DestroyAndWait( GameObject.Find( "Simple Track" ) );
}

[Test]
Expand Down Expand Up @@ -397,13 +392,18 @@ private Track CreateSimpleTrack()
{
GameObject root = new GameObject("Simple Track");

var refBody = Factory.Create<RigidBody>( );
refBody.transform.parent = root.transform;
refBody.GetComponent<RigidBody>().MotionControl = agx.RigidBody.MotionControl.KINEMATICS;

var (frontRB, frontWheel) = CreateWheel( Vector3.left, TrackWheelModel.Sprocket );
var (backRB, backWheel) = CreateWheel( Vector3.right );

var track = Factory.Create<Track>();
var trackComp = track.GetComponent<Track>();
track.AddComponent<TrackRenderer>();
trackComp.Width = 1;
trackComp.ReferenceObject = refBody;

trackComp.Add( frontWheel );
trackComp.Add( backWheel );
Expand Down
2 changes: 2 additions & 0 deletions Tests/Runtime/WireCutMergeTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AGXUnity;
using NUnit.Framework;
using System.Collections;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.TestTools;

Expand Down Expand Up @@ -135,6 +136,7 @@ public IEnumerator InvalidWinchesFailsMerge()
var result = SourceWire.Cut( Vector3.zero );
Assert.NotNull( result, "Cutting failed" );

LogAssert.Expect( LogType.Warning, new Regex( "Failed to merge wires.*" ) );
Assert.False( result.Merge( SourceWire ), "Merge should fail" );
// Need to wait a frame to ensure object is destroyed
yield return null;
Expand Down