Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading float numbers from external data CSV file fails. #534

Closed
malinb73 opened this issue Jul 18, 2024 · 4 comments · Fixed by #538
Closed

Loading float numbers from external data CSV file fails. #534

malinb73 opened this issue Jul 18, 2024 · 4 comments · Fixed by #538
Labels
bug Something isn't working

Comments

@malinb73
Copy link

--- Context ---
Built fmusim for Windows:
Platform: x86_64-windows
CMake Generator: Visual Studio 16 2019
Build type: Debug

Git commit checked:
Revision: 6d3a981
Author: Torsten Sommer torsten.sommer@3ds.com
Date: 7/5/2024 11:19:21 AM
Message: Fix variable index in fmi3{Get|Set}Binary() (#531)

--- Description ---
The error happens when importing external data from a CSV file and amongst other different inputs there are also inputs having float types.

Example:
time,s8_in,s16_in,array1D_in,float32_in
0,1,2,3 4 5,12.34

The error happens randomly.
The error message is: "Failed to reallocate memory."
The error occurs in fmusim/FMIStaticInput.c in function:
FMIStatus FMIApplyInput(FMIInstance* instance, const FMIStaticInput* input, double time, bool discrete, bool continuous, bool afterEvent)
at line 276:
CALL(FMIRealloc((void**)&input->buffer, requiredBufferSize));
The reason is requiredBufferSize variable has sometimes a very huge value due to some wrong memory read which is based on row variable.
This row variable is calculated in the while block from lines 255, see: "while (row < input->nRows - 2) {...."
Changing the while condition to "while (row < input->nRows - 1)" seems to solve the problem.
Can you check please?

@t-sommer t-sommer added the bug Something isn't working label Jul 22, 2024
@t-sommer
Copy link
Collaborator

Can you reproduce the problem if you use an input file with at least 3 rows?

E.g.

time,s8_in,s16_in,array1D_in,float32_in
0,1,2,3 4 5,12.34
1,1,2,3 4 5,12.34
2,1,2,3 4 5,12.34

@malinb73
Copy link
Author

Hi Sommer,

I made again 3 tests and this is the status:

  1. tested with 0.0.31

    • for 1 line fails
    • for more that 1 line ok
  2. tested with commit Revision: 6d3a981

    • for 1 line fails
    • for more that 1 line ok
  3. tested with my fix

    • for 1 line ok
    • for more that 1 line ok

I am not saying that I understood completely the code of FMIApplyInput() function from FMIStaticInput.c but the fix suggested is based on next fact:
I compared the code which fails from:
if (continuous && variable->variability == FMIContinuous)
with the code which works fine from:
else if (discrete && (variable->variability == FMIDiscrete || variable->variability == FMITunable))
and beside the specific code which handles FMIFloat32Type and FMIFloat64Type the notable difference is
while (row < input->nRows - 2)
VS.
while (row < input->nRows - 1)
Playing around with this condition and changing it to "row < input->nRows - 1" proved that worked fine also for floats (variability = FMIContinuous)

t-sommer added a commit to t-sommer/Reference-FMUs that referenced this issue Jul 23, 2024
@malinb73
Copy link
Author

Hi Sommer,
I can confirm that now it works as expected.
Can you tell me when is scheduled the next release having this fix?
Thank you,
Bogdan

@t-sommer
Copy link
Collaborator

You can download the binaries directly from the CI: https://github.com/modelica/Reference-FMUs/actions/runs/10073277513/artifacts/1734054905

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants