diff --git a/src/serialization/sb3.js b/src/serialization/sb3.js index 39f8d85f3..254257069 100644 --- a/src/serialization/sb3.js +++ b/src/serialization/sb3.js @@ -447,6 +447,13 @@ const serializeTarget = function (target, extensions) { obj.broadcasts = vars.broadcasts; [obj.blocks, targetExtensions] = serializeBlocks(target.blocks); obj.comments = serializeComments(target.comments); + + // TODO remove this check/patch when (#1901) is fixed + if (target.currentCostume < 0 || target.currentCostume >= target.costumes.length) { + log.warn(`currentCostume property for target ${target.name} is out of range`); + target.currentCostume = MathUtil.clamp(target.currentCostume, 0, target.costumes.length - 1); + } + obj.currentCostume = target.currentCostume; obj.costumes = target.costumes.map(serializeCostume); obj.sounds = target.sounds.map(serializeSound);