From e015287f9c2bcd8ce8c9669b23588e001805bd5a Mon Sep 17 00:00:00 2001 From: Andreas <38031952+AnHeuermann@users.noreply.github.com> Date: Mon, 3 Jul 2023 10:40:35 +0200 Subject: [PATCH] Assert number of base clocks equals initialized base clocks. (#10910) - Prevents segmentation faults, but doesn't fix the underlying issue. --- OMCompiler/Compiler/Template/CodegenC.tpl | 1 + OMCompiler/SimulationRuntime/c/simulation/solver/synchronous.c | 1 + 2 files changed, 2 insertions(+) diff --git a/OMCompiler/Compiler/Template/CodegenC.tpl b/OMCompiler/Compiler/Template/CodegenC.tpl index 4c74c8d915e..741986166e4 100644 --- a/OMCompiler/Compiler/Template/CodegenC.tpl +++ b/OMCompiler/Compiler/Template/CodegenC.tpl @@ -330,6 +330,7 @@ template functionInitSynchronous(list clockedPartitions, Strin void <%symbolName(modelNamePrefix,"function_initSynchronous")%>(DATA *data, threadData_t *threadData) { TRACE_PUSH + assertStreamPrint(threadData, data->modelData->nBaseClocks==<%listLength(clockedPartitions)%>, "Number of base clocks doens't match numer of clocks that are initialized! Code generation error!"); data->simulationInfo->baseClocks = calloc(<%listLength(clockedPartitions)%>, sizeof(BASECLOCK_DATA)); <%body%> diff --git a/OMCompiler/SimulationRuntime/c/simulation/solver/synchronous.c b/OMCompiler/SimulationRuntime/c/simulation/solver/synchronous.c index 6cea6b7b3e1..f72f84d6361 100644 --- a/OMCompiler/SimulationRuntime/c/simulation/solver/synchronous.c +++ b/OMCompiler/SimulationRuntime/c/simulation/solver/synchronous.c @@ -59,6 +59,7 @@ void initSynchronous(DATA* data, threadData_t *threadData, modelica_real startTi /* Error check */ for(i=0; imodelData->nBaseClocks; i++) { for(j=0; jsimulationInfo->baseClocks[i].nSubClocks; j++) { + assertStreamPrint(threadData, data->simulationInfo->baseClocks[i].subClocks != NULL, "Initialization of synchronous systems failed: baseclocks[%i]->subClocks is NULL!", i); assertStreamPrint(threadData, data->simulationInfo->baseClocks[i].subClocks[j].solverMethod != NULL, "Continuous clocked systems aren't supported yet."); assertStreamPrint(threadData, floorRat(data->simulationInfo->baseClocks[i].subClocks[j].shift) >= 0, "Shift of sub-clock is negative. Sub-clocks aren't allowed to fire before base-clock."); }