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

Commit 18ed650

Browse files
committed
Handle errors during FMI initialization
1 parent da38b3e commit 18ed650

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
@@ -317,6 +317,8 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
317317
fmi2Boolean visible, fmi2Boolean loggingOn) {
318318
// ignoring arguments: fmuResourceLocation, visible
319319
ModelInstance *comp;
320+
int fmi2callbacksOK = 0;
321+
threadData_t *threadData = NULL;
320322
if (!functions->logger) {
321323
return NULL;
322324
}
@@ -336,9 +338,8 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
336338
comp = (ModelInstance *)functions->allocateMemory(1, sizeof(ModelInstance));
337339
if (comp) {
338340
DATA* fmudata = NULL;
339-
MODEL_DATA* modelData = NULL;
340-
SIMULATION_INFO* simInfo = NULL;
341-
threadData_t *threadData = NULL;
341+
MODEL_DATA* modelData = NULL;
342+
SIMULATION_INFO* simInfo = NULL;
342343
int i;
343344

344345
comp->instanceName = (fmi2String)functions->allocateMemory(1 + strlen(instanceName), sizeof(char));
@@ -393,6 +394,9 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
393394
#endif
394395
/* read input vars */
395396
/* input_function(comp->fmuData); */
397+
MMC_INIT(X);
398+
pthread_setspecific(mmc_thread_data_key, threadData);
399+
MMC_TRY_INTERNAL(mmc_jumper)
396400
#if !defined(OMC_NUM_NONLINEAR_SYSTEMS) || OMC_NUM_NONLINEAR_SYSTEMS>0
397401
/* allocate memory for non-linear system solvers */
398402
initializeNonlinearSystems(comp->fmuData, comp->threadData);
@@ -409,6 +413,11 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
409413
/* allocate memory for state selection */
410414
initializeStateSetJacobians(comp->fmuData, comp->threadData);
411415
#endif
416+
fmi2callbacksOK = 1;
417+
MMC_CATCH_INTERNAL(mmc_jumper)
418+
if (!fmi2callbacksOK) {
419+
return NULL;
420+
}
412421
#ifdef FMU_EXPERIMENTAL
413422
/* allocate memory for Jacobian */
414423
comp->_has_jacobian = !comp->fmuData->callback->initialAnalyticJacobianA(comp->fmuData, comp->threadData);

0 commit comments

Comments
 (0)