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