Skip to content

Commit

Permalink
Fix out-of-bounds textures in [combine (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
OgelGames authored Apr 19, 2024
1 parent e5f7343 commit 4fb53b6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,11 @@ signs_lib.charwidth_wide32 = build_char_db(32)

local math_max = math.max

local function fill_line(x, y, w, c, font_size, colorbgw)
local function fill_line(x, y, w, c, font_size, colorbgw, line_width)
c = c or "0"
local tex = { }
for xx = 0, math.max(0, w), colorbgw do
for xx = 0, w, colorbgw do
if x + xx > line_width then break end
table.insert(tex, (":%d,%d=signs_lib_color_"..font_size.."px_%s.png"):format(x + xx, y, c))
end
return table.concat(tex)
Expand Down Expand Up @@ -583,9 +584,10 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
end
end
if w then
width = width + w + 1
width = width + w
if width >= (line_width - cwidth_tab[" "]) then
width = 0
break
else
maxw = math_max(width, maxw)
end
Expand Down Expand Up @@ -615,9 +617,10 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
else
local w = cwidth_tab[c]
if w then
width = width + w + 1
width = width + w
if width >= (line_width - cwidth_tab[" "]) then
width = 0
break
else
maxw = math_max(width, maxw)
end
Expand All @@ -633,7 +636,7 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
end
i = i + 1
end
width = width + cwidth_tab[" "] + 1
width = width + cwidth_tab[" "]
maxw = math_max(width, maxw)
table.insert(words, { chars=chars, w=ch_offs })
end
Expand All @@ -652,17 +655,16 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
for word_i, word in ipairs(words) do
local xoffs = (xpos - start_xpos)
if (xoffs > 0) and ((xoffs + word.w) > maxw) then
table.insert(texture, fill_line(xpos, ypos, maxw, "n", font_size, colorbgw))
xpos = start_xpos
ypos = ypos + line_height + def.line_spacing
lineno = lineno + 1
if lineno >= def.number_of_lines then break end
table.insert(texture, fill_line(xpos, ypos, maxw, cur_color, font_size, colorbgw))
table.insert(texture, fill_line(xpos, ypos, maxw, cur_color, font_size, colorbgw, line_width))
end
for ch_i, ch in ipairs(word.chars) do
if ch.col ~= cur_color then
cur_color = ch.col
table.insert(texture, fill_line(xpos + ch.off, ypos, maxw, cur_color, font_size, colorbgw))
table.insert(texture, fill_line(xpos + ch.off, ypos, maxw, cur_color, font_size, colorbgw, line_width))
end
table.insert(texture, (":%d,%d=%s"):format(xpos + ch.off, ypos, ch.tex))
end
Expand All @@ -671,11 +673,9 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
(":%d,%d="):format(xpos + word.w, ypos) .. char_tex(font_name, " ")
)
xpos = xpos + word.w + cwidth_tab[" "]
if xpos >= (line_width + cwidth_tab[" "]) then break end
end

table.insert(texture, fill_line(xpos, ypos, maxw, "n", font_size, colorbgw))
table.insert(texture, fill_line(start_xpos, ypos + line_height, maxw, "n", font_size, colorbgw))
table.insert(texture, fill_line(xpos, ypos, maxw, "n", font_size, colorbgw, line_width))
table.insert(texture, fill_line(start_xpos, ypos + line_height, maxw, "n", font_size, colorbgw, line_width))

return table.concat(texture), lineno
end
Expand Down

3 comments on commit 4fb53b6

@tenplus1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This merge has broken signs, words are now cut off and not wrapped properly in some instances, and OOB errors still occur.

e.g. "This is an example sign with a long line of text."

@OgelGames
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird, I tested the changes multiple times and they worked :/

Also, you could have said something about it in the 2 weeks the PR was sitting there waiting...

@tenplus1
Copy link
Contributor

@tenplus1 tenplus1 commented on 4fb53b6 Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OgelGames - This was the first time I managed to sit down and actually check some things in Minetest, time is expensive lately.

Please sign in to comment.