From dada8de750b19abf450befbc0563f5853a3bbff2 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 23 Jul 2023 16:55:16 +0200 Subject: removed negative chunks --- src/tiledmap.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/tiledmap.c b/src/tiledmap.c index 6d33463..ea587cc 100644 --- a/src/tiledmap.c +++ b/src/tiledmap.c @@ -127,6 +127,11 @@ void commitChunk(TiledMap * tiledMap, CachedChunk * cached) { } void unloadChunk(TiledMap * tiledMap, CachedChunk * cached) { + + // do not cache an unloaded chunk + if (cached->chunk == NULL) + return; + // commit a chunk before unloading commitChunk(tiledMap, cached); @@ -191,6 +196,9 @@ Tile getChunkedTile(TiledMap *tiledMap, int x, int y) { int chunkX = (x - inChunkX) / tiledMap->chunkWidth; int chunkY = (y - inChunkY) / tiledMap->chunkHeight; + if (x < 0 || y < 0) + return 0; + CachedChunk * cached = loadChunk(tiledMap, chunkX, chunkY); if (cached == NULL) return 0; -- cgit v1.2.1