From 1e5c7aa4211edfc15fdb85f084297b2ed546bac3 Mon Sep 17 00:00:00 2001 From: Galunid Date: Sat, 27 Apr 2024 07:12:48 +0200 Subject: [PATCH] Use dbg.dassert + additional null guard --- frontend/document/koptinterface.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend/document/koptinterface.lua b/frontend/document/koptinterface.lua index c166998eb..953b00107 100644 --- a/frontend/document/koptinterface.lua +++ b/frontend/document/koptinterface.lua @@ -1064,6 +1064,10 @@ function KoptInterface:getWordFromReflowPosition(doc, boxes, pos) local pageno = pos.page local scratch_reflowed_page_boxes = self:getReflowedTextBoxesFromScratch(doc, pageno) + if not DEBUG.dassert(scratch_reflowed_boxes and next(scratch_reflowed_word_boxes) ~= nil, "scratch_reflowed_boxes shouldn't be nil/{}") then + return + end + local scratch_reflowed_word_box = self:getWordFromBoxes(scratch_reflowed_page_boxes, pos) local reflowed_page_boxes = self:getReflowedTextBoxes(doc, pageno) @@ -1237,10 +1241,15 @@ function KoptInterface:getTextFromReflowPositions(doc, native_boxes, pos0, pos1) local reflowed_page_boxes = self:getReflowedTextBoxes(doc, pageno) local scratch_reflowed_word_box0 = self:getWordFromBoxes(scratch_reflowed_page_boxes, pos0) - if not scratch_reflowed_word_box0 or next(scratch_reflowed_word_box0) == nil then return end + if not DEBUG.dassert(scratch_reflowed_word_box0 and next(scratch_reflowed_word_box0) ~= nil, "scratch_reflowed_word_box0 shouldn't be nil/{}") then + return + end + local reflowed_word_box0 = self:getWordFromBoxes(reflowed_page_boxes, pos0) local scratch_reflowed_word_box1 = self:getWordFromBoxes(scratch_reflowed_page_boxes, pos1) - if not scratch_reflowed_word_box1 or next(scratch_reflowed_word_box1) == nil then return end + if not DEBUG.dassert(scratch_reflowed_word_box1 and next(scratch_reflowed_word_box1) ~= nil, "scratch_reflowed_word_box1 shouldn't be nil/{}") then + return + end local reflowed_word_box1 = self:getWordFromBoxes(reflowed_page_boxes, pos1) local reflowed_pos_abs0 = scratch_reflowed_word_box0.box:center()