Fixed locking up when performing text wrapping due to text width check not being satisfied

This commit is contained in:
2021-11-17 22:30:30 -06:00
parent c1b25d2045
commit 6af384536a

View File

@@ -72,8 +72,13 @@ module CyberarmEngine
line_start = 0 line_start = 0
line_end = copy.length line_end = copy.length
stalled = false
stalled_interations = 0
max_stalled_iterations = 10
checked_copy_length = line_width(copy[line_start..line_end])
# find length of lines # find length of lines
while line_width(copy[line_start..line_end]) > max_width while line_width(copy[line_start..line_end]) > max_width && stalled_interations < max_stalled_iterations
search_start = line_start search_start = line_start
search_end = line_end search_end = line_end
@@ -107,6 +112,13 @@ module CyberarmEngine
end end
breaks << line_start breaks << line_start
# Prevent locking up due to outer while loop text width < max_width check not being satisfied.
stalled = checked_copy_length == line_width(copy[line_start..line_end])
checked_copy_length = line_width(copy[line_start..line_end])
stalled_interations += 1 if stalled
stalled_interations = 0 unless stalled
end end
breaks.each_with_index do |pos, index| breaks.each_with_index do |pos, index|