@@ -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