Crash when generating imagetable

Mac, SDK 1.11.1

In a project I try to generate my own image table but it leads to a lot of unexpected behaviours. In the worst case the simulator crashes.

What I try to do is to create a new image table with and after to set the different indexes with setImage(). I encountered the following issues:

  • doesn't take into account the cellsWide argument.
  • It seems the first index has to have an image.
  • If I try to set an image to multiples indexes, the Simulator will crash.



local tile = "box" )
local iw, ih = tile:getSize()

local cw, ch = 2, 2
local tileset = cw*ch, cw )

-- Issue #1: return the wrong size, [4, 1] instead of [2,2] 
print( "Tileset size", tileset:getSize() )

-- Issue #2
-- if the first index is set, it is rendering but getImage() doesn't return nil for indexes that are not set, size can be incorrect
tileset:setImage(1, tile)

-- Issue #3
-- if the first index is not set, getImage() always returns nil
-- tileset:setImage(2, tile)
-- tileset:setImage(3, tile)
-- tileset:setImage(4, tile)

-- Issue #4, if the first index is set and another one is also set, crash might happens
-- tileset:setImage(1, tile)
-- tileset:setImage(2, tile)

function playdate.update()

	for cx = 1, cw do
		for cy = 1, ch do
			local tile = tileset:getImage(cx, cy)
			print("tileset coordinates:", cx, cy)
			if tile then
				print("image size:", tile:getSize())
				tile:draw( cx*iw, cy*ih )

I guess I'm not too surprised there are bugs lurking in there, it's not a heavily trafficked part of the API. I've filed that, and I'll take a look at it once I can find the time. Thanks!