sdk 1.10.0, mac, Simulator
It seems that using something like this crashes the simulator (not sure about hardware)
function playdate.update()
gfx.pushContext()
for i = 1,60 do
-- additional drawing here
coroutine.yield()
end
gfx.popContext() -- reset any drawing state modifications
playdate.drawFPS(0,0)
updateBlinkers()
updateTimers()
end
The problem can be observed on this branch of my project I prepared:
Crazy-Gravity-Playdate-bug-context-yield.zip (3.0 MB)
To reproduce, fly the plane into the wall. (The explosion animation uses coroutine.yield)
After the animation ends, the simulator will crash.
To fix the bug, either remove the pair of push/PopContext calls in main.lua OR remove the coroutine.yield() call from gameViewModel.lua
I was not able to create a minimal example here though.
Some snippets from the project:
main.lua
local activeScreen = GameScreen()
function playdate.update()
gfx.pushContext()
activeScreen:update()
gfx.popContext() -- reset any drawing state modifications
playdate.drawFPS(0,0)
updateBlinkers()
updateTimers()
end
gameViewModel.lua
if collision and explosion == nil and not Debug then
if Sounds then thrust_sound:stop() end
thrust = 0
explosion = GameExplosion()
print("KABOOM")
while explosion:update() do
calcPlane() -- keep updating plane as a ghost target for camera
CalcGameCam()
RenderGame()
playdate.drawFPS(0,0)
coroutine.yield() -- let system update the screen
end
DecreaseLife()
end
Removing the push/popContext is actually viable for me, I had it included as a safety measure because perhaps the activeScreen
would invert colors or set a clipRect etc, making the fps counter invisible.
The hunch I have is that there is something abbout the pushContext not being matched by a popContext when coroutine.yield is called in between to end the frame, leading to an illegal state in the SDK, which crashes the simulator.
I understand this project might be too big to peruse entirely, but perhaps the problem is in plain sight and there is something for me to learn regarding the workings of these methods.