diff --git a/runtimes/native/src/framebuffer.c b/runtimes/native/src/framebuffer.c index 1a472615..c6e67ef3 100644 --- a/runtimes/native/src/framebuffer.c +++ b/runtimes/native/src/framebuffer.c @@ -334,8 +334,8 @@ void w4_framebufferRect (int x, int y, int width, int height) { int startY = w4_max(0, y); int endXUnclamped = x + width; int endYUnclamped = y + height; - int endX = w4_min(endXUnclamped, WIDTH); - int endY = w4_min(endYUnclamped, HEIGHT); + int endX = w4_max(0, w4_min(endXUnclamped, WIDTH)); + int endY = w4_max(0, w4_min(endYUnclamped, HEIGHT)); uint8_t dc01 = drawColors[0]; uint8_t dc0 = dc01 & 0xf; diff --git a/runtimes/web/src/framebuffer.ts b/runtimes/web/src/framebuffer.ts index 7381c1b5..42da37fb 100644 --- a/runtimes/web/src/framebuffer.ts +++ b/runtimes/web/src/framebuffer.ts @@ -101,8 +101,8 @@ export class Framebuffer { const startY = Math.max(0, y); const endXUnclamped = x + width; const endYUnclamped = y + height; - const endX = Math.min(endXUnclamped, WIDTH); - const endY = Math.min(endYUnclamped, HEIGHT); + const endX = Math.max(0, Math.min(endXUnclamped, WIDTH)); + const endY = Math.max(0, Math.min(endYUnclamped, HEIGHT)); const drawColors = this.drawColors[0]; const dc0 = drawColors & 0xf;