Skip to content

SimulationRuntime: Fix segfault when FMU model calls terminate#16024

Open
jschueller wants to merge 1 commit into
OpenModelica:masterfrom
jschueller:issue9474
Open

SimulationRuntime: Fix segfault when FMU model calls terminate#16024
jschueller wants to merge 1 commit into
OpenModelica:masterfrom
jschueller:issue9474

Conversation

@jschueller

Copy link
Copy Markdown
Contributor

When a Modelica model calls terminate() inside an FMU, the generated code longjmps via MMC_THROW(). The FMU runtime catch blocks in internalEventUpdate and internal_CompletedIntegratorStep treated this identically to assertion failures, returning fmi2Error without setting the terminateSimulation flag. Importers like PyFMI then crashed with a segfault upon receiving fmi2Error.

Fix by:

  • Adding _terminate_simulation_requested flag to ModelInstance structs
  • Providing an FMU-specific omc_terminate that sets this flag before throwing, letting catch blocks distinguish terminate from assertions
  • Setting eventInfo.terminateSimulation = fmiTrue and returning OK instead of error when terminate is detected
  • Checking terminateSimulation in fmi2DoStep/fmu3DoStepInternal to exit the integration loop cleanly

Closes #9474

When a Modelica model calls terminate() inside an FMU, the generated code
longjmps via MMC_THROW(). The FMU runtime catch blocks in
internalEventUpdate and internal_CompletedIntegratorStep treated this
identically to assertion failures, returning fmi2Error without setting
the terminateSimulation flag. Importers like PyFMI then crashed with a
segfault upon receiving fmi2Error.

Fix by:
- Adding _terminate_simulation_requested flag to ModelInstance structs
- Providing an FMU-specific omc_terminate that sets this flag before
  throwing, letting catch blocks distinguish terminate from assertions
- Setting eventInfo.terminateSimulation = fmiTrue and returning OK
  instead of error when terminate is detected
- Checking terminateSimulation in fmi2DoStep/fmu3DoStepInternal to exit
  the integration loop cleanly

Closes OpenModelica#9474
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

Successfully merging this pull request may close these issues.

iPython kernel crashes and restarts when simulating FMU including "terminate" command

2 participants