Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 3879132

Browse files
committed
Handle errors during FMI initialization
1 parent deeabde commit 3879132

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

SimulationRuntime/c/util/omc_error.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ void debugStreamPrintWithEquationIndexes(int stream, int indentNext, const int *
404404

405405
static inline jmp_buf* getBestJumpBuffer(threadData_t *threadData)
406406
{
407+
if (!threadData) {
408+
fprintf(stderr, "OpenModelica threadData is NULL; this should not be possible");
409+
abort();
410+
}
407411
switch (threadData->currentErrorStage) {
408412
case ERROR_EVENTSEARCH:
409413
case ERROR_SIMULATION:

SimulationRuntime/fmi/export/fmi2/fmu2_model_interface.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
298298
fmi2Boolean visible, fmi2Boolean loggingOn) {
299299
// ignoring arguments: fmuResourceLocation, visible
300300
ModelInstance *comp;
301+
int fmi2callbacksOK = 0;
302+
threadData_t *threadData = NULL;
301303
if (!functions->logger) {
302304
return NULL;
303305
}
@@ -317,9 +319,8 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
317319
comp = (ModelInstance *)functions->allocateMemory(1, sizeof(ModelInstance));
318320
if (comp) {
319321
DATA* fmudata = NULL;
320-
MODEL_DATA* modelData = NULL;
321-
SIMULATION_INFO* simInfo = NULL;
322-
threadData_t *threadData = NULL;
322+
MODEL_DATA* modelData = NULL;
323+
SIMULATION_INFO* simInfo = NULL;
323324
int i;
324325

325326
comp->instanceName = (fmi2String)functions->allocateMemory(1 + strlen(instanceName), sizeof(char));
@@ -374,6 +375,9 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
374375
#endif
375376
/* read input vars */
376377
/* input_function(comp->fmuData); */
378+
MMC_INIT(X);
379+
pthread_setspecific(mmc_thread_data_key, threadData);
380+
MMC_TRY_INTERNAL(mmc_jumper)
377381
#if !defined(OMC_NUM_NONLINEAR_SYSTEMS) || OMC_NUM_NONLINEAR_SYSTEMS>0
378382
/* allocate memory for non-linear system solvers */
379383
initializeNonlinearSystems(comp->fmuData, comp->threadData);
@@ -390,6 +394,11 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
390394
/* allocate memory for state selection */
391395
initializeStateSetJacobians(comp->fmuData, comp->threadData);
392396
#endif
397+
fmi2callbacksOK = 1;
398+
MMC_CATCH_INTERNAL(mmc_jumper)
399+
if (!fmi2callbacksOK) {
400+
return NULL;
401+
}
393402
#ifdef FMU_EXPERIMENTAL
394403
/* allocate memory for Jacobian */
395404
comp->_has_jacobian = !comp->fmuData->callback->initialAnalyticJacobianA(comp->fmuData, comp->threadData);

0 commit comments

Comments
 (0)