--- gigedit/trunk/src/gigedit/CombineInstrumentsDialog.cpp 2020/05/29 23:25:06 3782 +++ gigedit/trunk/src/gigedit/CombineInstrumentsDialog.cpp 2020/05/30 00:14:27 3783 @@ -412,6 +412,23 @@ }; typedef std::vector CopyAssignSchedule; +/** @brief Constrain @a dimCase according to @a rgn's dimension zones. + * + * To avoid @a dimCase being an invalid dimension region selection on @a rgn, + * this function automatically wraps (if required) the individual dimension case + * entries according to region's actual amount of dimension zones. + * + * @param dimCase - dimension case to be potentially corrected + * @param rgn - the region upon @a dimCase shall be corrected for + */ +static void wrapDimCase(DimensionCase& dimCase, gig::Region* rgn) { + for (auto& it : dimCase) { + gig::dimension_def_t* def = rgn->GetDimensionDefinition(it.first); + const int zones = (def) ? def->zones : 1; + it.second %= zones; + } +} + /** @brief Schedule copying DimensionRegions from source Region to target Region. * * Schedules copying the entire articulation informations (including sample @@ -456,6 +473,13 @@ uint dstDimValues[8] = {}; DimensionCase srcDimCase = dimCase; DimensionCase dstDimCase = dimCase; + + // source might have less zones than destination, so to prevent output + // instrument ending up with NULL samples in some of the dimension + // zones, wrap here the source zone according to the amount of zones the + // source really has + wrapDimCase(srcDimCase, inRgn); + srcDimCase[mainDim] = iSrcMainBit; dstDimCase[mainDim] = iDstMainBit;