Subtitle wordwrap can cause an infinite loop

Bug #409151 reported by Spiky Caterpillar
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ren'Py
Fix Released
Medium
Tom Rothamel

Bug Description

Attempting to render excessively long text with layout='subtitle' and no spaces to break on will cause a tight infinite loop.

(Testcase:
    $ x = 30
label wrapfail:
    show expression Text('M'*x,xmaximum=300,yminimum=20,color='#0f0',yalign=0.5,size=15,layout='subtitle')
    "%(x)d"
    $ x += 1
    jump wrapfail
)

The actual loop is in renpy/display/text.py's subtitle_text_layout function. I think the best fix is probably to break words longer than the desired width into single-character tokens; a patch to do so follows. (It does, however, not
generate the optimum layout with the string of Ms - not sure if that's a problem in my change or a problem in the original subtitle layout, but it's better than an infinite loop.)

*** text.py.orig 2009-08-04 17:18:15.000000000 -0700
--- text.py 2009-08-04 18:27:50.000000000 -0700
***************
*** 548,553 ****
--- 548,564 ----
      lines_last = [ ]

      for triples in pars:
+ x = 0
+ newtriples = []
+ while x<len(triples):
+ triplewidth = layout_width([triples[x],],justify)
+ if triplewidth<=width or triples[x][0]!='word':
+ newtriples.append(triples[x])
+ else:
+ for char in triples[x][2]:
+ newtriples.append(('word',triples[x][1],char))
+ x+=1
+ triples = newtriples

          sumwidths = layout_width(triples, justify)
(End patch)

Revision history for this message
Tom Rothamel (renpytom) wrote :

This seems as sensible a behavior as any. Could you post your patch as an attachment, as it seems to have been reformatted by launchpad.

Changed in renpy:
status: New → Triaged
importance: Undecided → Medium
assignee: nobody → renpytom (renpytom)
milestone: none → 6.10
Revision history for this message
Spiky Caterpillar (spikycaterpillar) wrote :

Here it is.

Tom Rothamel (renpytom)
Changed in renpy:
status: Triaged → Fix Committed
Tom Rothamel (renpytom)
Changed in renpy:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.