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

Segmentation fault after assert #212

Open
AnHeuermann opened this issue Nov 21, 2023 · 1 comment
Open

Segmentation fault after assert #212

AnHeuermann opened this issue Nov 21, 2023 · 1 comment

Comments

@AnHeuermann
Copy link

AnHeuermann commented Nov 21, 2023

Issue

I added regression tests for OpenModelica and they are testing some OpenModelica FMUs with FMI.jl.

For model Modelica.Fluid.Examples.PumpingSystem FMI.jl is crashing when simulating the generated FMU and an assert is encountered.

OMSimulator is triggering the assert as well, but finishes the simulation with success.

How to reproduce

using FMI
using OMJulia

omc = OMJulia.OMCSession()
mkpath("temp")
OMJulia.API.cd(omc, "temp")

OMJulia.API.loadModel(omc, "Modelica"; priorityVersion = ["4.0.0"], requireExactVersion = true)
fmuPath = OMJulia.API.buildModelFMU(omc, "Modelica.Fluid.Examples.PumpingSystem")
OMJulia.quit(omc)

#fmuPath = joinpath("temp","Modelica.Fluid.Examples.PumpingSystem.fmu")
fmu = FMI.fmiLoad(fmuPath)
solution = FMI.fmiSimulate(fmu; showProgress=false)
LOG_ASSERT        | warning | [C:/Users/USERNAME/AppData/Roaming/.openmodelica/libraries/Modelica 4.0.0+maint.om/Fluid/Interfaces.mo:1027:9-1032:39:writable]
|                 | |       | The following assertion has been violated at time 0.000000
|                 | |       | ((pipe.flowModel.m_flows[1] >= 0.0 and pipe.flowModel.m_flows[1] <= 1e5)) --> "Variable violating min/max constraint: 0.0 <= pipe.flowModel.m_flows[1] <= 1e5, has value: -141.424"

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x7fffa3977f7f -- setjmpex at C:\WINDOWS\System32\msvcrt.dll (unknown line)
in expression starting at D:\path\to\test.jl:14
setjmpex at C:\WINDOWS\System32\msvcrt.dll (unknown line)
omc_assert_fmi at D:/path/to/temp/FMU/sources/fmi-export\fmu2_model_interface.c.inc:228

Windows FMU with debug symbols (remove the .zip extension):
Modelica.Fluid.Examples.PumpingSystem.fmu.zip

Error log:
error.log

Versions 'n stuff

  • OS: Windows 11
  • Julia v1.9.3
  • FMI.jl v0.13.0
  • OMJulia.jl v0.3.0
  • OpenModelica v1.23.0-dev-79-g7d33402a02-cmake
@AnHeuermann
Copy link
Author

I'm not sure what exactly the issue is, but I guess it has something to do with the long jump function used when throwing an assert in the C code of the FMU:

static void omc_assert_fmi(threadData_t *threadData, FILE_INFO info, const char *msg, ...)
{
  va_list args;
  va_start(args, msg);
  omc_assert_fmi_common(threadData, fmi2Error, LOG_STATUSERROR, info, msg, args);
  va_end(args);
  MMC_THROW_INTERNAL(); // <---- EXCEPTION_ACCESS_VIOLATION
}
#define MMC_THROW_INTERNAL() {longjmp(*threadData->mmc_jumper,1);}

The issue happens on Windows and Linux, so I rule out some compatibility issues between the different C runtimes on Windows.

On Ubuntu the call stack looks like:

libc.so.6!__libc_siglongjmp(struct __jmp_buf_tag * env, int val) (longjmp.c:32)
Modelica_Fluid_Examples_PumpingSystem.so!omc_assert_fmi(threadData_t * threadData, FILE_INFO info, const char * msg) (\path\to\temp\FMU\sources\fmi-export\fmu2_model_interface.c.inc:228)
Modelica_Fluid_Examples_PumpingSystem.so!omc_Modelica_Media_Water_IF97__Utilities_BaseIF97_Basic_tsat(threadData_t * threadData, modelica_real _p) (\path\to\temp\FMU\sources\Modelica_Fluid_Examples_PumpingSystem_functions.c:13630)
[...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant