我的问题是,当您调整窗口大小时,通过在控制台中按一个键退出,love.exe将崩溃。仅在使用 Canvas 时会发生这种情况。
重现崩溃的方法如下:
关闭
如果仅运行代码,则此操作将不起作用,因为需要在conf.lua中启用控制台,因此请运行love文件。如果未调整窗口大小,则不会发生崩溃。
崩溃
function draw()
love.graphics.circle("fill", 100, 100, 50) -- Draw circle
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setCanvas()
love.graphics.draw(canvas, 0, 0, 0, 2) -- 200% zoom
love.graphics.setCanvas(canvas)
love.graphics.present() -- Refresh screen
end
love.window.setMode(500, 500)
canvas = love.graphics.newCanvas(1000, 1000) -- Create canvas
love.graphics.setCanvas(canvas)
draw() -- Draw circle
love.timer.sleep(1)
love.window.setMode(800, 800) -- Resize window
love.graphics.setCanvas(canvas)
draw() -- Redraw circle
love.timer.sleep(2)
love.window.close()
print("Should crash when you quit this by pressing key")
os.execute("pause")
love.event.push("quit")
不崩溃
function draw()
love.graphics.circle("fill", 100, 100, 50) -- Draw circle
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setCanvas()
love.graphics.draw(canvas, 0, 0, 0, 2) -- 200% zoom
love.graphics.setCanvas(canvas)
love.graphics.present() -- Refresh screen
end
love.window.setMode(500, 500)
canvas = love.graphics.newCanvas(1000, 1000) -- Create canvas
love.graphics.setCanvas(canvas)
draw() -- Draw circle
love.timer.sleep(1)
-- Window was resized once, before canvas creation --> no crash
love.window.close()
os.execute("pause")
love.event.push("quit")
Download .love file
请注意,我也将此问题发布在LOVE论坛here上,但尚未找到好的答案。我想也许我可以在这里得到答案。
最佳答案
Changing the display mode may have side effects: for example, canvases will be cleared and values sent to shaders with Shader:send will be erased. Make sure to save the contents of canvases beforehand or re-draw to them afterward if you need to.
您可以通过在setMode操作期间将渲染目标重置为主屏幕来维护 Canvas 数据并防止崩溃:
love.graphics.setCanvas() -- Reset render target to screen
love.window.setMode(800, 800) -- Resize window
love.graphics.setCanvas(canvas) -- Render to canvas again
HTH,
Xeozim
关于canvas - 如果在创建 Canvas 后调整了窗口的大小,退出时Love2d崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38965754/