Skip to content

Commit

Permalink
Fix errors when creating new RayCast sensor (#5261)
Browse files Browse the repository at this point in the history
* check if tag and angle is null

* add test

* changelog
  • Loading branch information
Ruo-Ping Dong authored Apr 14, 2021
1 parent 8fee3cb commit 08a66c4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions com.unity.ml-agents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ This results in much less memory being allocated during inference with `CameraSe
settings. Unfortunately, this may require retraining models if it changes the resulting order of the sensors
or actuators on your system. (#5194)
- Removed additional memory allocations that were occurring due to assert messages and iterating of DemonstrationRecorders. (#5246)
- Fixed a bug where agent trying to access unintialized fields when creating a new RayPerceptionSensorComponent on an agent. (#5261)

## [1.9.1-preview] - 2021-04-13
### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public struct RayPerceptionInput
/// <returns></returns>
public int OutputSize()
{
return (DetectableTags.Count + 2) * Angles.Count;
return ((DetectableTags?.Count ?? 0) + 2) * (Angles?.Count ?? 0);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,19 @@ public void TestStaticPerceiveNoTags()
Assert.AreEqual(-1, castOutput.RayOutputs[0].HitTagIndex);
}
}

[Test]
public void TestCreateDefault()
{
SetupScene();
var obj = new GameObject("agent");
var perception = obj.AddComponent<RayPerceptionSensorComponent3D>();

Assert.DoesNotThrow(() =>
{
perception.CreateSensors();
});
}
#endif
}
}

0 comments on commit 08a66c4

Please sign in to comment.