Don't crash the editor if drawing a view fails

This commit is contained in:
Jeremy Penner 2020-12-30 12:01:29 -05:00
parent 01138ea05c
commit aa6e25d5b1
2 changed files with 13 additions and 3 deletions

View file

@ -237,8 +237,14 @@ function core.push_clip_rect(x, y, w, h)
w, h = r-x, b-y w, h = r-x, b-y
table.insert(core.clip_rect_stack, { x, y, w, h }) table.insert(core.clip_rect_stack, { x, y, w, h })
renderer.set_clip_rect(x, y, w, h) renderer.set_clip_rect(x, y, w, h)
return (#core.clip_rect_stack) - 1
end end
function core.pop_clip_rect_to(length)
while #core.clip_rect_stack > length do
core.pop_clip_rect()
end
end
function core.pop_clip_rect() function core.pop_clip_rect()
table.remove(core.clip_rect_stack) table.remove(core.clip_rect_stack)

View file

@ -365,9 +365,13 @@ function Node:draw()
self:draw_tabs() self:draw_tabs()
end end
local pos, size = self.active_view.position, self.active_view.size local pos, size = self.active_view.position, self.active_view.size
core.push_clip_rect(pos.x, pos.y, size.x + pos.x % 1, size.y + pos.y % 1) local clipstate = core.push_clip_rect(pos.x, pos.y, size.x + pos.x % 1, size.y + pos.y % 1)
self.active_view:draw() xpcall(function() self.active_view:draw() end,
core.pop_clip_rect() function(msg)
love.graphics.setCanvas(nil)
common.draw_text(style.font, { common.color "#ff0000" }, msg .. "\n" .. debug.traceback(), "left", pos.x, pos.y, size.x, size.y)
end)
core.pop_clip_rect_to(clipstate)
else else
local x, y, w, h = self:get_divider_rect() local x, y, w, h = self:get_divider_rect()
renderer.draw_rect(x, y, w, h, style.divider) renderer.draw_rect(x, y, w, h, style.divider)