From 772daea335b8b2394d2a8fbe9fc81dcbfa1a506e Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Wed, 14 Apr 2021 14:54:38 -0700 Subject: [PATCH 1/4] check if tag and angle is null --- com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs b/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs index 319f675087..fa2ce8ff61 100644 --- a/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs +++ b/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs @@ -78,7 +78,7 @@ public struct RayPerceptionInput /// public int OutputSize() { - return (DetectableTags.Count + 2) * Angles.Count; + return (DetectableTags?.Count ?? 0 + 2) * Angles?.Count ?? 0; } /// From 96fcda0c08481003519abb2b2ebeff2b5602bf6c Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Wed, 14 Apr 2021 15:06:41 -0700 Subject: [PATCH 2/4] add test --- .../Runtime/Sensor/RayPerceptionSensorTests.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/com.unity.ml-agents/Tests/Runtime/Sensor/RayPerceptionSensorTests.cs b/com.unity.ml-agents/Tests/Runtime/Sensor/RayPerceptionSensorTests.cs index 2145d98712..a4c7badc59 100644 --- a/com.unity.ml-agents/Tests/Runtime/Sensor/RayPerceptionSensorTests.cs +++ b/com.unity.ml-agents/Tests/Runtime/Sensor/RayPerceptionSensorTests.cs @@ -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(); + + Assert.DoesNotThrow(() => + { + perception.CreateSensors(); + }); + } #endif } } From 65657a5d31d314a94021482e05ec6fb4129d3e86 Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Wed, 14 Apr 2021 15:25:40 -0700 Subject: [PATCH 3/4] changelog --- com.unity.ml-agents/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index f75162e9d5..600095a306 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -63,6 +63,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 From 30413d39900df70bf294da60af5b346fc7ee56dc Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Wed, 14 Apr 2021 16:02:57 -0700 Subject: [PATCH 4/4] parentheses are important --- com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs b/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs index fa2ce8ff61..e225859c33 100644 --- a/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs +++ b/com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs @@ -78,7 +78,7 @@ public struct RayPerceptionInput /// public int OutputSize() { - return (DetectableTags?.Count ?? 0 + 2) * Angles?.Count ?? 0; + return ((DetectableTags?.Count ?? 0) + 2) * (Angles?.Count ?? 0); } ///