From 56ce6d15b678ab34c0bf603b55448a59e8aa6ab6 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Wed, 30 Dec 2020 12:01:29 -0500 Subject: [PATCH] Don't crash the editor if drawing a view fails --- vendor/lite/data/core/init.lua | 6 ++++++ vendor/lite/data/core/rootview.lua | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/vendor/lite/data/core/init.lua b/vendor/lite/data/core/init.lua index bff35c2..3af4844 100644 --- a/vendor/lite/data/core/init.lua +++ b/vendor/lite/data/core/init.lua @@ -237,8 +237,14 @@ function core.push_clip_rect(x, y, w, h) w, h = r-x, b-y table.insert(core.clip_rect_stack, { x, y, w, h }) renderer.set_clip_rect(x, y, w, h) + return (#core.clip_rect_stack) - 1 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() table.remove(core.clip_rect_stack) diff --git a/vendor/lite/data/core/rootview.lua b/vendor/lite/data/core/rootview.lua index 389525f..ca29726 100644 --- a/vendor/lite/data/core/rootview.lua +++ b/vendor/lite/data/core/rootview.lua @@ -365,9 +365,13 @@ function Node:draw() self:draw_tabs() end 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) - self.active_view:draw() - core.pop_clip_rect() + local clipstate = core.push_clip_rect(pos.x, pos.y, size.x + pos.x % 1, size.y + pos.y % 1) + xpcall(function() self.active_view:draw() end, + 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 local x, y, w, h = self:get_divider_rect() renderer.draw_rect(x, y, w, h, style.divider)