Long playdate.update() can make the simulator spin the rainbow wheel 🌈

It seems that updates that are longer that the set refresh rate will impact how the simulator run and can make it hangs. The effect is cumulative so if multiple update in a row are long, the simulator will hang more and more to the point of being unresponsive.

It run fine on the console.
I use the Mac version.

This is of course a very edge case since this is unlikely that game will have updates that take this long on a computer.

import 'CoreLibs/utilities/printer'
import 'CoreLibs/sprites'
import 'CoreLibs/graphics'

white = playdate.graphics.kColorWhite
black = playdate.graphics.kColorBlack

local gameTime = 0
local frameCount = 0

playdate.display.setRefreshRate(30)

function playdate.update()
	gameTime = gameTime + 1 / playdate.display.getRefreshRate()
	frameCount = frameCount + 1

	playdate.graphics.clear( white )

	playdate.graphics.fillCircleAtPoint(
		200 + math.cos(gameTime)*70,
		120 + math.sin(gameTime)*70,
		30)

	playdate.drawFPS(5, 5)

	playdate.graphics.drawText("Frame "..frameCount, 5, 220)

	local waitStart = playdate.getCurrentTimeMilliseconds()
	-- local waitTime = 34 -- chock up the simulator at 30Hz
	local waitTime = 25 -- fine at 30Hz but chock up at 60Hz
	repeat until (playdate.getCurrentTimeMilliseconds()-waitStart)>=waitTime

	print(frameCount)
end
1 Like

But in case it happens, I think it's still better to skip some frames or just pause the simulator itself and display an alert to notify the user that the game exceeds device resources.
(I mean, it's still 'better' than let it pile up until the whole application freezes..)

Hi, please don’t reply to ancient bug reports. It’s likely the issue has been fixed or has become irrelevant and there’s little value to revisit such topics. If you have encountered this issue recently, please open a new thread with up to date information.

2 Likes