From c702b35f38a4e9fd3dbdfbabf946148dbb3dda20 Mon Sep 17 00:00:00 2001 From: xmug Date: Wed, 19 Oct 2022 16:53:26 +0800 Subject: [PATCH] Fix bug with stacking sensor(#5790) grid sensor and all PNG compression used will face this bug when channel number is larger than 3 && used stacking observation (stack > 1) --- .../Runtime/Sensors/StackingSensor.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/com.unity.ml-agents/Runtime/Sensors/StackingSensor.cs b/com.unity.ml-agents/Runtime/Sensors/StackingSensor.cs index 710c58a821..26fd8995b3 100644 --- a/com.unity.ml-agents/Runtime/Sensors/StackingSensor.cs +++ b/com.unity.ml-agents/Runtime/Sensors/StackingSensor.cs @@ -82,7 +82,18 @@ public StackingSensor(ISensor wrapped, int numStackedObservations) if (m_WrappedSensor.GetCompressionSpec().SensorCompressionType != SensorCompressionType.None) { m_StackedCompressedObservations = new byte[numStackedObservations][]; - m_EmptyCompressedObservation = CreateEmptyPNG(); + + // Generate Single Empty PNG + Byte[] singleEmptyPNG = CreateEmptyPNG(); + List emptyCompressedObservationList = new List(); + + // Combine Multiple Empty PNGs for channels more than 3 + for (int i = 0; i < (m_WrappedSpec.Shape[^1] + 2) / 3; i++) + { + emptyCompressedObservationList.AddRange(singleEmptyPNG); + } + m_EmptyCompressedObservation = emptyCompressedObservationList.ToArray(); + for (var i = 0; i < numStackedObservations; i++) { m_StackedCompressedObservations[i] = m_EmptyCompressedObservation;