summaryrefslogtreecommitdiff
path: root/src/tiledmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tiledmap.c')
-rw-r--r--src/tiledmap.c8
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;