diff options
author | davidovski <david@davidovski.xyz> | 2023-07-23 16:55:16 +0200 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2023-07-23 16:55:16 +0200 |
commit | dada8de750b19abf450befbc0563f5853a3bbff2 (patch) | |
tree | cf64765efa1457044635bc667dd1c5b7bb9ce314 /src | |
parent | c726acd0467906afee74afb7051bb2e705e26565 (diff) |
removed negative chunks
Diffstat (limited to 'src')
-rw-r--r-- | src/tiledmap.c | 8 |
1 files changed, 8 insertions, 0 deletions
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; |