snapshot_canvas = function(global_viewport, globalw, globalh)
-- Render the canvas at pixel perfect resolution.
Saved_screen = {w=App.screen.width, h=App.screen.height}
App.screen.width, App.screen.height = globalw, globalh
local saved_viewport = Viewport
Viewport = copy_viewport(global_viewport)
Viewport.zoom = 1.0
A()
-- Things go very bad if the canvas gets too large.
-- Even though it's in memory, LÖVE seems to use memory in the graphics card to write graphics to it.
-- If the canvas is too big to fit in graphics card memory, you get an unrecoverable error.
-- So I try to keep it from getting too large. But with a hard-coded constant because
-- I don't know how to measure how much graphics memory a computer has.
-- It might not protect older computers.
-- This is the place to experiment with if you run into an error about SDL limits and contacting Kartik.
Disallow_error_recovery_on_key_release = true
local w = math.min(16000, App.screen.width)
local h = math.min(16000, App.screen.height)
print('creating canvas', w, h)
local canvas = love.graphics.newCanvas(w, h)
love.graphics.setCanvas(canvas)
on.draw()
love.graphics.setCanvas()
Disallow_error_recovery_on_key_release = nil
Viewport = saved_viewport
App.screen.width,App.screen.height = Saved_screen.w, Saved_screen.h
Saved_screen = nil
return canvas
end