Skip to content

Commit d937af3

Browse files
committed
Engine: in DynamicSprite.Crop() also fixup x,y crop position if needed
1 parent 5a23ef8 commit d937af3

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

Engine/ac/dynamicsprite.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ void DynamicSprite_Crop(ScriptDynamicSprite *sds, int x, int y, int width, int h
196196
data_to_game_coords(&width, &height);
197197

198198
// Clamp the cropped size to the valid area of the original image
199-
if ((width > game.SpriteInfos[sds->slot].Width - x) || (height > game.SpriteInfos[sds->slot].Height - y))
199+
if ((x < 0) || (y < 0) || (width > game.SpriteInfos[sds->slot].Width - x) || (height > game.SpriteInfos[sds->slot].Height - y))
200200
debug_script_warn("DynamicSprite.Crop: requested to crop to an area outside of the source image: image is %dx%d, crop area %d,%d %dx%d",
201201
game.SpriteInfos[sds->slot].Width, game.SpriteInfos[sds->slot].Height, x, y, width, height);
202-
width = std::min(width, game.SpriteInfos[sds->slot].Width - x);
203-
height = std::min(height, game.SpriteInfos[sds->slot].Height - y);
202+
Math::ClampLength(x, width, 0, game.SpriteInfos[sds->slot].Width);
203+
Math::ClampLength(y, height, 0, game.SpriteInfos[sds->slot].Height);
204204

205205
if (width <= 0 || height <= 0)
206206
return; // cannot crop to zero size

0 commit comments

Comments
 (0)