fix: crash when dragging out of the window

This commit is contained in:
orangerot 2025-10-15 16:02:36 +02:00
parent a65050fbb3
commit 6f3e302e09

9
game.c
View file

@ -220,9 +220,10 @@ void init(struct image canvas) {
void draw( struct image canvas, struct image texture, size_t xpos, size_t ypos, bool vertical) {
for (size_t y = 0; y < texture.height; y++) {
for (size_t x = 0; x < texture.width; x++) {
size_t canvas_y = vertical ? x : y;
size_t canvas_x = vertical ? y : x;
canvas.buf[(ypos + canvas_y) * canvas.width + xpos + canvas_x] = texture.buf[y * texture.width + x];
int canvas_y = (vertical ? x : y) + ypos;
int canvas_x = (vertical ? y : x) + xpos;
if (canvas_x < 0 || canvas_x >= (int) canvas.width - 1 || canvas_y < 0 || canvas_y >= (int) canvas.height - 1) continue;
canvas.buf[canvas_y * canvas.width + canvas_x] = texture.buf[y * texture.width + x];
}
}
}
@ -280,7 +281,7 @@ void render(struct image canvas) {
// active
if (has_active) {
draw(canvas, red_and_peach_dominoes[active.back.val][active.front.val], CLAMP(mouse_x + active.front.x, 0, canvas.width), CLAMP(mouse_y + active.front.y, 0, canvas.height), active.front.vertical);
draw(canvas, red_and_peach_dominoes[active.back.val][active.front.val], mouse_x + active.front.x, mouse_y + active.front.y, active.front.vertical);
}
// character