Calling lockFocus(img)/unlockFocus within a pushContext(img)/popContext

Seeing this error when I attempt to lockFocus on an image while in a push/pop context on another image.

main.lua:93: no pushed context!
stack traceback:
	[C]: in field 'popContext'
	main.lua:93: in function <main.lua:75>

Some pseudo code to reproduce (I believe):

local main_image =, 240)
local sub_image =, 240)


That’s correct (if confusing), unlockFocus() pops the entire stack. Per Inside Playdate: returns drawing to the frame buffer.

If you use push/popContext() instead it’ll work correctly

1 Like

Woah! I think I must have just made some weird assumptions. Apologies. I just weirdly assumed lockFocus was a lightweight version that didn’t save and restore graphics context but instead used what was whatever already on the stack. My bad. Excuse me while I go make sure I’m using this correctly throughout my code. :grimacing: