Possible bug with tintTile() and touch scrolling?

I’m using the tintTile() function along with touch scrolling (NOT the one that’s built-in to the latest ver, but the older one from the castledemo) and whenever I have a tile that’s undergoing the tinting process and moves off-screen (out of the camera view), I get this error:

“mte.lua: 12309: attempt to call method ‘setFillColor’ (a nil value)”

and the relevant line in the code is:

“tile:setFillColor(tile.currentColor[1], tile.currentColor[2], tile.currentColor[3])”
 

I’m guessing that this has to do with the tile no longer being available because it’s no longer visible on the screen. Not positive if it’s a bug in MTE or in my own code (my test was fairly simple though, basically tint one tile over a long period of time and then scroll off screen).

I did a check to see if the tile was nil but it looks like it still exists at that point.

Hello tablecloth,

You found a bug, and you’re right about the cause as well. I check for the tile’s existence in the other tint functions, but this one slipped under the radar. If you go to line 12295 of main.lua you’ll see the Tint Tiles block:

--Tint tiles for key,value in pairs(tintingTiles) do local tile = tintingTiles[key] tile.currentColor[1] = tile.currentColor[1] - tile.deltaTint[1][1] tile.currentColor[2] = tile.currentColor[2] - tile.deltaTint[2][1] tile.currentColor[3] = tile.currentColor[3] - tile.deltaTint[3][1] for i = 1, 3, 1 do if tile.currentColor[i] \> 1 then tile.currentColor[i] = 1 end if tile.currentColor[i] \< 0 then tile.currentColor[i] = 0 end end tile:setFillColor(tile.currentColor[1], tile.currentColor[2], tile.currentColor[3]) table.remove(tile.deltaTint[1], 1) table.remove(tile.deltaTint[2], 1) table.remove(tile.deltaTint[3], 1) if not tile.deltaTint[1][1] then tile.deltaTint = nil tintingTiles[tile] = nil end end

Replace it with this modified version to correct the problem:

--Tint tiles for key,value in pairs(tintingTiles) do local tile = tintingTiles[key] if tileObjects[tile.layer][tile.locX] and tileObjects[tile.layer][tile.locX][tile.locY] then tile.currentColor[1] = tile.currentColor[1] - tile.deltaTint[1][1] tile.currentColor[2] = tile.currentColor[2] - tile.deltaTint[2][1] tile.currentColor[3] = tile.currentColor[3] - tile.deltaTint[3][1] for i = 1, 3, 1 do if tile.currentColor[i] \> 1 then tile.currentColor[i] = 1 end if tile.currentColor[i] \< 0 then tile.currentColor[i] = 0 end end tile:setFillColor(tile.currentColor[1], tile.currentColor[2], tile.currentColor[3]) table.remove(tile.deltaTint[1], 1) table.remove(tile.deltaTint[2], 1) table.remove(tile.deltaTint[3], 1) if not tile.deltaTint[1][1] then tile.deltaTint = nil tintingTiles[tile] = nil end else tintingTiles[key] = nil end end

I’m not releasing an update this week because I’m in the middle of implementing map stitching, but the fix will be included in the next release.

Excellent, the fix worked perfectly. Thanks Dyson!

Hello tablecloth,

You found a bug, and you’re right about the cause as well. I check for the tile’s existence in the other tint functions, but this one slipped under the radar. If you go to line 12295 of main.lua you’ll see the Tint Tiles block:

--Tint tiles for key,value in pairs(tintingTiles) do local tile = tintingTiles[key] tile.currentColor[1] = tile.currentColor[1] - tile.deltaTint[1][1] tile.currentColor[2] = tile.currentColor[2] - tile.deltaTint[2][1] tile.currentColor[3] = tile.currentColor[3] - tile.deltaTint[3][1] for i = 1, 3, 1 do if tile.currentColor[i] \> 1 then tile.currentColor[i] = 1 end if tile.currentColor[i] \< 0 then tile.currentColor[i] = 0 end end tile:setFillColor(tile.currentColor[1], tile.currentColor[2], tile.currentColor[3]) table.remove(tile.deltaTint[1], 1) table.remove(tile.deltaTint[2], 1) table.remove(tile.deltaTint[3], 1) if not tile.deltaTint[1][1] then tile.deltaTint = nil tintingTiles[tile] = nil end end

Replace it with this modified version to correct the problem:

--Tint tiles for key,value in pairs(tintingTiles) do local tile = tintingTiles[key] if tileObjects[tile.layer][tile.locX] and tileObjects[tile.layer][tile.locX][tile.locY] then tile.currentColor[1] = tile.currentColor[1] - tile.deltaTint[1][1] tile.currentColor[2] = tile.currentColor[2] - tile.deltaTint[2][1] tile.currentColor[3] = tile.currentColor[3] - tile.deltaTint[3][1] for i = 1, 3, 1 do if tile.currentColor[i] \> 1 then tile.currentColor[i] = 1 end if tile.currentColor[i] \< 0 then tile.currentColor[i] = 0 end end tile:setFillColor(tile.currentColor[1], tile.currentColor[2], tile.currentColor[3]) table.remove(tile.deltaTint[1], 1) table.remove(tile.deltaTint[2], 1) table.remove(tile.deltaTint[3], 1) if not tile.deltaTint[1][1] then tile.deltaTint = nil tintingTiles[tile] = nil end else tintingTiles[key] = nil end end

I’m not releasing an update this week because I’m in the middle of implementing map stitching, but the fix will be included in the next release.

Excellent, the fix worked perfectly. Thanks Dyson!

Hi Dyson,

I have a similar problem.  When I tint a tile and it goes just offscreen the tint is lost.  It’s still flagged as tinted though I think.  I’ve tried extending changing the culling region to see if that would help but it doesn’t.

Thanks

scrub that, I was doing something wrong with the culling margin in set camera it seems.  With a suitable sized margin it does indeed keep the tile tinted if it leaves the screen.

Thanks

Hi Dyson,

I have a similar problem.  When I tint a tile and it goes just offscreen the tint is lost.  It’s still flagged as tinted though I think.  I’ve tried extending changing the culling region to see if that would help but it doesn’t.

Thanks

scrub that, I was doing something wrong with the culling margin in set camera it seems.  With a suitable sized margin it does indeed keep the tile tinted if it leaves the screen.

Thanks