From b7580bbfe01d634247c4caf8f0a81c7460c435a6 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 6 Jan 2019 00:00:53 -0500 Subject: render: texture: Fix error when splitting certain textures. The split-texture procedure would throw an exception in the event that the image width/height could not be divided by tile width/height with 0 remainder. * chickadee/render/texture.scm (split-texture): Floor the results of dividing image dimensions by tile dimensions and ensure they are exact integers. --- chickadee/render/texture.scm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/chickadee/render/texture.scm b/chickadee/render/texture.scm index 3b1cb04..f225770 100644 --- a/chickadee/render/texture.scm +++ b/chickadee/render/texture.scm @@ -313,10 +313,8 @@ This type of texture atlas layout is very common for tile map terrain." (let* ((w (texture-width texture)) (h (texture-height texture)) - (sw (/ tile-width w)) - (th (/ tile-height h)) - (rows (/ (- h margin) (+ tile-height spacing))) - (columns (/ (- w margin) (+ tile-width spacing))) + (rows (inexact->exact (floor (/ (- h margin) (+ tile-height spacing))))) + (columns (inexact->exact (floor (/ (- w margin) (+ tile-width spacing))))) (v (make-vector (* rows columns)))) (define (make-tile tx ty) (let* ((x (+ (* tx (+ tile-width spacing)) margin)) -- cgit v1.2.3