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

Commit 56502c6

Browse files
committed
Handle errors during FMI initialization
1 parent c5383bb commit 56502c6

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
@@ -458,6 +458,10 @@ void debugStreamPrintWithEquationIndexes(int stream, int indentNext, const int *
458458

459459
static inline jmp_buf* getBestJumpBuffer(threadData_t *threadData)
460460
{
461+
if (!threadData) {
462+
fprintf(stderr, "OpenModelica threadData is NULL; this should not be possible");
463+
abort();
464+
}
461465
switch (threadData->currentErrorStage) {
462466
case ERROR_EVENTSEARCH:
463467
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
@@ -291,6 +291,8 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
291291
fmi2Boolean visible, fmi2Boolean loggingOn) {
292292
// ignoring arguments: fmuResourceLocation, visible
293293
ModelInstance *comp;
294+
int fmi2callbacksOK = 0;
295+
threadData_t *threadData = NULL;
294296
if (!functions->logger) {
295297
return NULL;
296298
}
@@ -310,9 +312,8 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
310312
comp = (ModelInstance *)functions->allocateMemory(1, sizeof(ModelInstance));
311313
if (comp) {
312314
DATA* fmudata = NULL;
313-
MODEL_DATA* modelData = NULL;
314-
SIMULATION_INFO* simInfo = NULL;
315-
threadData_t *threadData = NULL;
315+
MODEL_DATA* modelData = NULL;
316+
SIMULATION_INFO* simInfo = NULL;
316317
int i;
317318

318319
comp->instanceName = (fmi2String)functions->allocateMemory(1 + strlen(instanceName), sizeof(char));
@@ -367,6 +368,9 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
367368
/* read input vars */
368369
//input_function(comp->fmuData);
369370
/* initial sample and delay before initial the system */
371+
MMC_INIT(X);
372+
pthread_setspecific(mmc_thread_data_key, threadData);
373+
MMC_TRY_INTERNAL(mmc_jumper)
370374
comp->fmuData->callback->callExternalObjectConstructors(comp->fmuData, comp->threadData);
371375
/* allocate memory for non-linear system solvers */
372376
initializeNonlinearSystems(comp->fmuData, comp->threadData);
@@ -376,6 +380,11 @@ fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2Str
376380
initializeMixedSystems(comp->fmuData, comp->threadData);
377381
/* allocate memory for state selection */
378382
initializeStateSetJacobians(comp->fmuData, comp->threadData);
383+
fmi2callbacksOK = 1;
384+
MMC_CATCH_INTERNAL(mmc_jumper)
385+
if (!fmi2callbacksOK) {
386+
return NULL;
387+
}
379388

380389
#ifdef FMU_EXPERIMENTAL
381390
/* allocate memory for Jacobian */

0 commit comments

Comments
 (0)