Tilemap.set_tile error "SetGridShapHull" (SOLVED)


My tilemap is setting the tiles correctly, but each call to tilemap.set_tile triggers this error:

I’m confused because the the tile indexes I’m using are visually correct and definitely within the bounds of the tilemap. :confused:


Can you please also share the code where you call tilemap.set_tile() and preferrably also a screenshot of the tilemap with it’s layers?


Hi Britzl,

This is the base tilemap that gets updated with tilemap.set_tile:

These tilemaps are used as definitions to reference:

Here is the code where the tilemap.set_tile is being called:

--uses 16-bit bitmasking to calculate tile value
local function calcTileValue(grid, x, y)
	local northCoord = y - 1
	local north = (grid[northCoord] and grid[northCoord][x] > 0) and 1 or 0

	local eastCoord = x + 1
	local east = (grid[y][eastCoord] and grid[y][eastCoord] > 0) and 1 or 0

	local southCoord = y + 1
	local south = (grid[southCoord] and grid[southCoord][x] > 0) and 1 or 0

	local westCoord = x - 1
	local west = (grid[y][westCoord] and grid[y][westCoord] > 0) and 1 or 0

	return north + (2 * east) + (4 * south) + (8 * west)

[table] filterCallbacks
[function] filterCallbacks[gridValue]
local function iterateGrid(grid, filterCallbacks)
	for y=1,#grid do
		for x=1,#grid[1] do
			local gridValue = grid[y][x]
			local callback = filterCallbacks[gridValue]			
			if callback then
				callback(calcTileValue(grid, x, y), x, y)

local function getTileDefs(url, layer)
	local _,_,w,h = tilemap.get_bounds(url)
	local defs = {}
	local list = {}
	local y = h
	while y > 0 do
		for x=1,w do
			local tile = tilemap.get_tile(url, layer, x, y)
			defs[tile] = true
			table.insert(list, tile)
		y = y - 1
	return {
		hash = defs,
		list = list

local function makeList(length, fillValue)
	local list = {}
	for i=1,length do
		list[i] = fillValue
	return list

local function randomTile(tileList)
	local listIndex = math.random(1, #tileList)
	local tileIndex = tileList[listIndex]
	return tileIndex

local function makeGridFromTilemap()
	local impassableTiles = getTileDefs("#map-impassables", "walls")
	local groundTiles = getTileDefs("#map-ground", "base")
	local groundCoverTiles = getTileDefs("#map-ground", "extras")
	local originX,originY,w,h = tilemap.get_bounds("#map-objects")
	local grid = {}
	local adjustedH = h -1
	local adjustedW = w - 1
	-- setup binary grid data
	for y=1,adjustedH do
		local flippedY = h - y
		grid[y] = makeList(adjustedW, 0)
		for x=1,adjustedW do
			local curTileIndex = tilemap.get_tile("#map-objects", "wall", x, flippedY)
			local isWallTile = impassableTiles.hash[curTileIndex]
			if isWallTile then
				grid[y][x] = 1

	local function setGroundTile(x, y)
		local groundTileIndex = groundTiles.list[1]
		tilemap.set_tile("#map-objects", "ground", x, y, groundTileIndex)		

	local function addGroundCoverTile(x, y)
		local groundCoverTileIndex = randomTile(groundCoverTiles.list)
		tilemap.set_tile("#map-objects", "ground2", x, y, groundCoverTileIndex)
	tilemapBitmask.iterateGrid(grid, {
		[0] = function(_, x, y)
			local flippedY = h - y
			setGroundTile(x, flippedY)
			local shouldAddGroundCover = math.random(0, 1) == 1
			if shouldAddGroundCover then
				addGroundCoverTile(x, flippedY)
		[1] = function(tileValue, x, y)	
			local listIndex = tileValue + 1
			local tileIndex = impassableTiles.list[listIndex]
			local flippedY = h - y
			tilemap.set_tile("#map-objects", "wall", x, flippedY, tileIndex)

			setGroundTile(x, flippedY)
			grid[y][x] = 1
	return grid


Hmm, nothing obvious. The error actually relates to when the collision shape gets updated for the tilemap. Would you mind sharing the project with me (bjorn.ritzl@king.com)?


So, I updated the collision for the tilesource and that fixed it :smile:. It wasn’t obvious from the error message that this was the culprit though…

In any event, thanks a bunch for the pointer Britzl.


I’m also getting the following error…

ERROR:GAMESYS: SetGridShapHull: specified hull index is out of bounds.

…upon calling:

tilemap.set_tile("/level#tilemap", "select", pos.x, pos.y, 0)

The function works as expected (the tile at position ‘pos’ is removed) but the error is still displayed in the console.

I’ve recently added some collision groups to the tileset and the error started after that.

Any ideas please?


We added a range check for that function last sprint, it might have triggered something. 0 is a valid number since it clears the tile, so it must be something else. Do you have a project or a repro case that I can take a look at?


Thanks - I can add you to the project if you’ve got an email address you’re happy to share?


Great! jhonny.goransson@king.com


Found the issue and submitted a fix. Thanks for reporting!