Skip to content

Commit

Permalink
SKA-436: Fixed binaries array variables handling (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
VJean-ThomasMasse authored and GitHub Enterprise committed Mar 27, 2024
1 parent aa71d94 commit fc11a74
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
12 changes: 4 additions & 8 deletions FmuImporter/FmiBridge/Binding/Fmi3Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit fc11a74

Please sign in to comment.