@@ -489,7 +489,19 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
489489 // Handle the case of dynamically sized columns. In this case the metadata passed
490490 // from the Block (containing DynamicSize) is modified with the length of the
491491 // vector that is going to be stored.
492+ // This is necessary in the pipeline for storing the metadata in the RTW file, which should
493+ // not have any dynamic size.
492494 const bool hasDynSizeColumns = (paramMD.cols == ParameterMetadata::DynamicSize);
495+ auto handleDynSizeColumns = [](int & sizeToUpdate, const int & realSize) -> const bool {
496+ if (realSize == ParameterMetadata::DynamicSize) {
497+ wbtError << " Trying to store the cols of a dynamically sized parameters, but the "
498+ << " metadata does not specify a valid size. Probably the block didn't "
499+ << " updat the size in its initialization phase." ;
500+ return false ;
501+ }
502+ sizeToUpdate = realSize;
503+ return true ;
504+ };
493505
494506 switch (paramMD.type ) {
495507 // SCALAR / VECTOR PARAMETERS
@@ -523,7 +535,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
523535 return false ;
524536 }
525537 if (hasDynSizeColumns) {
526- paramMD.cols = paramVector.size ();
538+ if (!handleDynSizeColumns (paramMD.cols , paramVector.size ())) {
539+ return false ;
540+ }
527541 }
528542 ok = parameters.storeParameter <double >(paramVector, paramMD);
529543 }
@@ -566,7 +580,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
566580 paramVector.push_back (value);
567581 }
568582 if (hasDynSizeColumns) {
569- paramMD.cols = paramVector.size ();
583+ if (!handleDynSizeColumns (paramMD.cols , paramVector.size ())) {
584+ return false ;
585+ }
570586 }
571587 ok = parameters.storeParameter <double >(paramVector, paramMD);
572588 break ;
@@ -588,7 +604,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
588604 paramVector.push_back (value);
589605 }
590606 if (hasDynSizeColumns) {
591- paramMD.cols = paramVector.size ();
607+ if (!handleDynSizeColumns (paramMD.cols , paramVector.size ())) {
608+ return false ;
609+ }
592610 }
593611 ok = parameters.storeParameter <std::string>(paramVector, paramMD);
594612 break ;
@@ -615,7 +633,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
615633 return false ;
616634 }
617635 if (hasDynSizeColumns) {
618- paramMD.cols = paramVector.size ();
636+ if (!handleDynSizeColumns (paramMD.cols , paramVector.size ())) {
637+ return false ;
638+ }
619639 }
620640 ok = parameters.storeParameter <double >(paramVector, paramMD);
621641 }
@@ -658,7 +678,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
658678 paramVector.push_back (value);
659679 }
660680 if (hasDynSizeColumns) {
661- paramMD.cols = paramVector.size ();
681+ if (!handleDynSizeColumns (paramMD.cols , paramVector.size ())) {
682+ return false ;
683+ }
662684 }
663685 ok = parameters.storeParameter <double >(paramVector, paramMD);
664686 break ;
@@ -682,7 +704,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
682704 paramVector.push_back (value);
683705 }
684706 if (hasDynSizeColumns) {
685- paramMD.cols = paramVector.size ();
707+ if (!handleDynSizeColumns (paramMD.cols , paramVector.size ())) {
708+ return false ;
709+ }
686710 }
687711 ok = parameters.storeParameter <std::string>(paramVector, paramMD);
688712 break ;
0 commit comments