From fc11a74adf8c669306c8d397986062409f80793a Mon Sep 17 00:00:00 2001 From: "Masse, Jean-Thomas" Date: Wed, 27 Mar 2024 13:28:35 +0100 Subject: [PATCH] SKA-436: Fixed binaries array variables handling (#90) --- CHANGELOG.md | 1 + FmuImporter/FmiBridge/Binding/Fmi3Binding.cs | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e320b6a..994388b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ The format is based on `Keep a Changelog (http://keepachangelog.com/en/1.0.0/) < * Fixed a possible StackOverflow exception if an FMU returns a discard or error status code * Fixed a possible stall of the SIL Kit component if the FMU component terminates unexpectedly * FMU Importer erroneously started SIL Kit lifecycle even if the initialization of the FMU or Importer failed +* Fixed a crash that occured if the FMU had array variables of Binary type. --- diff --git a/FmuImporter/FmiBridge/Binding/Fmi3Binding.cs b/FmuImporter/FmiBridge/Binding/Fmi3Binding.cs index 7ad7322..eb289b9 100644 --- a/FmuImporter/FmiBridge/Binding/Fmi3Binding.cs +++ b/FmuImporter/FmiBridge/Binding/Fmi3Binding.cs @@ -812,8 +812,7 @@ public override void SetValue(uint valueRef, byte[] data, int[] binSizes) var arraySize = 1; if (!isScalar) { - arraySize = BitConverter.ToInt32(data, 0); - data = data.Skip(4).ToArray(); + arraySize = binSizes.Length; if (binSizes.Sum() != data.Length) { @@ -849,10 +848,7 @@ public override void SetValue(uint valueRef, byte[] data, int[] binSizes) { valueRef }, - new[] - { - (IntPtr)data.Length - }, + Array.ConvertAll(binSizes, b => (IntPtr)b), values); foreach (var gcHandle in handlers) @@ -1479,15 +1475,15 @@ public ReturnVariable GetBinary(fmi3ValueReference[] valueReferences) throw new NullReferenceException("FMU was not initialized."); } - var valueSizes = new size_t[valueReferences.Length]; var nValues = CalculateValueLength(ref valueReferences); var result = new fmi3Binary[(int)nValues]; + var valueSizes = new IntPtr[(int)nValues]; ProcessReturnCode( _fmi3GetBinary( _component, valueReferences, - (size_t)valueReferences.Length, + (IntPtr)valueReferences.Length, valueSizes, result, nValues),