Skip to content

Commit 70d5420

Browse files
committed
PenLayer: Do not stamp if out of bounds
1 parent e16ef10 commit 70d5420

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/penlayer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ void PenLayer::stamp(IRenderedTarget *target)
213213

214214
const float stageWidth = m_engine->stageWidth() * m_scale;
215215
const float stageHeight = m_engine->stageHeight() * m_scale;
216+
217+
libscratchcpp::Rect bounds = target->getFastBounds();
218+
bounds.snapToInt();
219+
220+
if (!bounds.intersects(libscratchcpp::Rect(-stageWidth / 2, stageHeight / 2, stageWidth / 2, -stageHeight / 2)))
221+
return;
222+
216223
float x = 0;
217224
float y = 0;
218225
float angle = 180;
@@ -244,8 +251,6 @@ void PenLayer::stamp(IRenderedTarget *target)
244251
scaleX *= m_scale;
245252
scaleY *= m_scale;
246253

247-
libscratchcpp::Rect bounds = target->getFastBounds();
248-
bounds.snapToInt();
249254
const Texture &texture = target->cpuTexture();
250255

251256
if (!texture.isValid())

0 commit comments

Comments
 (0)