From bb8463f14a7ac62923f38fb0495b0614391677a5 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Tue, 8 Jan 2019 13:26:06 -0500 Subject: [PATCH] Log a warning for currentCostume out of range when incorrect project is being serialized. --- src/serialization/sb3.js | 7 +++++++ 1 file changed, 7 insertions(+) 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);