diff --git a/src/serialization/sb2.js b/src/serialization/sb2.js index b3dc19eef..2f7556341 100644 --- a/src/serialization/sb2.js +++ b/src/serialization/sb2.js @@ -684,7 +684,9 @@ const parseScratchObject = function (object, runtime, extensions, topLevel, zip, target.y = object.scratchY; } if (object.hasOwnProperty('direction')) { - target.direction = object.direction; + // Sometimes the direction can be outside of the range: LLK/scratch-gui#5806 + // wrapClamp it (like we do on RenderedTarget.setDirection) + target.direction = MathUtil.wrapClamp(object.direction, -179, 180); } if (object.hasOwnProperty('isDraggable')) { target.draggable = object.isDraggable; diff --git a/src/serialization/sb3.js b/src/serialization/sb3.js index 022064f3c..5eb60a5bf 100644 --- a/src/serialization/sb3.js +++ b/src/serialization/sb3.js @@ -1060,7 +1060,9 @@ const parseScratchObject = function (object, runtime, extensions, zip, assets) { target.y = object.y; } if (object.hasOwnProperty('direction')) { - target.direction = object.direction; + // Sometimes the direction can be outside of the range: LLK/scratch-gui#5806 + // wrapClamp it (like we do on RenderedTarget.setDirection) + target.direction = MathUtil.wrapClamp(object.direction, -179, 180); } if (object.hasOwnProperty('size')) { target.size = object.size;