My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 241: exception during incremental layout of empty document
5 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  r1chardj0n3s
Closed:  Mar 2008

Sign in to add a comment
Project Member Reported by r1chardj0n3s, Mar 5, 2008
Upon trying to assign new text to a Document instance, I get the following
traceback (in this case I replace it with an empty string but it's in the
delete that it breaks):

  File "bruce/", line 101, in on_key_press
    self.document.text = ''
  File "/usr/lib/python2.5/site-packages/pyglet/text/", line
282, in _set_text
    self.delete_text(0, len(self._text))
  File "/usr/lib/python2.5/site-packages/pyglet/text/", line
443, in delete_text
    self.dispatch_event('on_delete_text', start, end)
  File "/usr/lib/python2.5/site-packages/pyglet/", line 340, in
    if handler(*args):
  File "/usr/lib/python2.5/site-packages/pyglet/text/", line 1421,
in on_delete_text
  File "/usr/lib/python2.5/site-packages/pyglet/text/", line 1447,
in _update
    font = self.document.get_font(0, dpi=self._dpi)
  File "/usr/lib/python2.5/site-packages/pyglet/text/", line
657, in get_font
    return iter[position]
  File "/usr/lib/python2.5/site-packages/pyglet/text/", line
716, in __getitem__
    font_name, font_size, bold, italic = self.zip_iter[index]
  File "/usr/lib/python2.5/site-packages/pyglet/text/", line 403,
in __getitem__
    return [i[index] for i in self.range_iterators]
  File "/usr/lib/python2.5/site-packages/pyglet/text/", line 293,
in __getitem__
    self.start, self.end, self.value =

Mar 5, 2008
Project Member #1 r1chardj0n3s
To clarify, that's a FormattedDocument.
Mar 5, 2008
Project Member #2 r1chardj0n3s
While I'm at it, apparently UnformattedDocument doesn't like being give empty text
Mar 6, 2008
Project Member #3
Fixed in r1872.
Status: Fixed
Feb 5, 2009
I have version 1.1.2 but I'm still getting the very same problem. However it appears
to *only* happen with the combination of FormattedDocument and IncrementalTextLayout,
and after setting a style, and only if that style is one of font_name, font_size,
bold, italic, underline, leading, line_spacing, margin_top, or margin_bottom.

minimum code to reproduce it:

    import pyglet

    document = pyglet.text.document.FormattedDocument("")

    layout = pyglet.text.layout.IncrementalTextLayout(document, 50, 50)
    document.set_style(0, len(document.text), {"font_name": "Arial"})


    import pyglet

    document = pyglet.text.document.FormattedDocument("test")

    layout = pyglet.text.layout.IncrementalTextLayout(document, 50, 50)
    document.set_style(0, len(document.text), {"font_name": "Arial"})

    document.delete_text(0, len(document.text))

In the first example the traceback starts at set_style, and in the second it starts
at delete_text, but both end up with the same problem as above, beginning in _update.
Mar 26, 2009
Project Member #5
I can reproduce this bug by running the following code snippet (from pyglet-users) in
the svn trunk (rev 2445, using Intel Mac OS 10.5.6):

import pyglet
document = pyglet.text.document.FormattedDocument('A')
document.set_style(0, 1, dict(bold=True))
layout = pyglet.text.layout.IncrementalTextLayout(document,100,100)

I tried making a test case for it by adding one line to tests/text/ as shown
in the following diff, but running that test gets me an illegal instruction in
Python! Either I found an even worse bug, or I'm unknowingly violating the pyglet API.

% diff -c
***	2009-03-24 10:03:56.000000000 -0700
---	2009-03-26 14:45:15.000000000 -0700
*** 1,6 ****
  #!/usr/bin/env python
! '''Test that an empty document doesn't break.
  Press ESC to exit the test.
--- 1,9 ----
  #!/usr/bin/env python
! '''Test that an empty document doesn't break, if it is initialized with
! style bold = True.
! (See  issue 241 ,
  Press ESC to exit the test.
*** 29,34 ****
--- 32,38 ----
          self.document = doctype()
          self.layout = layout.IncrementalTextLayout(self.document,
              self.width, self.height, batch=self.batch)
+         self.document.set_style(0, len(self.document.text), {"bold": True})
      def on_draw(self):
          gl.glClearColor(1, 1, 1, 1)

% python
EIllegal instruction
Exit 132

(Note: that capital 'E' before 'Illegal' is really there and repeatable.)

% python
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin

The top of the C stack (according to Mac CrashReporter) looks like this:

OS Version:      Mac OS X 10.5.6 (9G55)
Report Version:  6

Exception Codes: 0x0000000000000001, 0x0000000000000000
Crashed Thread:  0

Thread 0 Crashed:
0   ???                           	0x002fccd8 0 + 3132632
1           	0x96b2957d
SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*,
HandlerCallRec*) + 405
2           	0x96b293e2 SendEventToEventTargetWithOptions + 58
3           	0x96bae58d PostActivateEvent + 381
4           	0x96bae01b HiliteAndActivateWindow + 381
5           	0x96debe0d
AdjustToNewWindowActivation(WindowData*, WindowContext*, OpaqueWindowPtr*, unsigned
char, WindowData*) + 141
6           	0x96bade42
PotentiallyAdjustActivationOnOrderIn(WindowData*, WindowData*) + 156
7           	0x96bac671 ShowWindow + 87
8   libffi.dylib                  	0x96e731dd .LCFI1 + 23
9   libffi.dylib                  	0x96e73771 ffi_call + 113
10                    	0x002b9814 _CallProc + 513
11                    	0x002b5f5f IsSimpleSubType + 3756
12  org.python.python             	0x00121505 PyObject_Call + 50
13  org.python.python             	0x0018f832 PyEval_EvalFrameEx + 17904
14  org.python.python             	0x00191173 PyEval_EvalCodeEx + 1638
15  org.python.python             	0x0018f79d PyEval_EvalFrameEx + 17755

Maybe this crash belongs in a new issue?
Mar 8, 2010
As others have said, this is not really fixed. See

(Sorry about the duplication. When I searched for existing issues I left the drop
down menu at "Open Issues" so this one didn't show up.)
Apr 27, 2010
Project Member #7
I think there are several different issues here, some of which are still open; see
also related  issue 429 . I'm going to try to sort this out, as follows.

* There is the original bug Richard reported in this issue (without a specific test
case). Presumably Alex fixed *something* with r1872, but I don't know how to find
that revision now that we've switched to mercurial, nor which svn branch(es) it was
fixed in. The reported original traceback is extremely similar to some that still
occur with open bugs (eg  issue 471 ). So my best guess is that there was a more
general bug (e.g. maybe it didn't depend on having any styled text), Alex fixed that,
but the same traceback still occurs in other cases.

I think it's simplest to consider that unknown original bug (i.e. this issue) to be
different than the newer bugs (since it was fixed and they are not). Therefore, this
issue can remain closed, and the subsequent comments can be treated as reporting
different bugs, some of which are already reported in different issues. 

Specifically, that means open  issue 471  is *not* a duplicate of this issue, even
though it has a similar traceback.

* Both code samples in comment 4, and the first one in comment 5, still fail for me
in the current hg head, i.e. pyglet 1.2dev, on Mac OS 10.6.3, using Python
2.6.2 installed from (FYI, I have no problems running that combination of
pyglet, python, and Mac OS in general, in spite of reported issues with similar
combinations but pyglet 1.1.3, e.g. in  issue 438 .) I will consider them to be part of
 issue 471 . (Two of them -- the ones with a non-empty document -- have almost
identical tracebacks, and the other one has a similar traceback, so they may still
turn out to involve two different bugs.)

I will refer to this from  issue 471 , so that whoever fixes that can make sure this
also fixes the code samples here in comments 4 and 5, and if not, open separate bug
reports for them.

* I didn't retry the Python crash reported in comment 5 lately. If I or anyone else
retries that and it still crashes or fails, it should be reported in its own new issue.
Apr 27, 2010
Project Member #8
FYI, I found the diffs and log entries from svn rev 1872 (and related rev 1873) in
which Alex fixed the original issue reported here. These make it clear
that the issue he fixed was "correctly initializing a layout displaying an empty
document", rather than "assigning empty text to an existing nonempty document" (as
most of the later-reported bugs are trying to do). (Looking at the code, this effect
of the change also looks plausible.) This confirms the idea that this issue is indeed
fixed, and  issue 471  is not a duplicate of it. 

This also makes it clear that, judging from the issue that was actually fixed, the
original summary "Document doesn't allow replacement of text" is no longer accurate.
(Maybe that bug was Richard's intent to report, but if so, refer to  issue 471  for
that, which is more related and still open.) So I will change this bug's summary to
describe what was actually fixed by the code change which closed the bug.

FYI (since I'm not sure if they're still accessible from google code -- certainly not
easily), here are the relevant svn revs and log entries:

[running in an old pyglet-svn directory]
% svn diff -c 1872
Index: tests/text/
--- tests/text/	(revision 1871)
+++ tests/text/	(revision 1872)
@@ -8,6 +8,8 @@
 __docformat__ = 'restructuredtext'
 __version__ = '$Id: 1754 2008-02-10 13:26:52Z Alex.Holkner $'
+__noninteractive = True
 import unittest
 from pyglet import app
Index: tests/plan.txt
--- tests/plan.txt	(revision 1871)
+++ tests/plan.txt	(revision 1872)
@@ -201,6 +201,7 @@
     text.RUNLIST                                GENERIC
+    text.EMPTY                                  GENERIC
     text.PLAIN                                  GENERIC
     text.STYLE                                  GENERIC
     text.ELEMENT                                GENERIC
Index: pyglet/text/
--- pyglet/text/	(revision 1871)
+++ pyglet/text/	(revision 1872)
@@ -1110,7 +1110,6 @@
             if line.paragraph_end:
                 y -= margin_bottom_iterator[line.start]
         line_index = start
         for line in lines[start:]:
             if line.paragraph_begin:
@@ -1447,6 +1446,7 @@
             font = self.document.get_font(0, dpi=self._dpi)
             self.lines[0].ascent = font.ascent
             self.lines[0].descent = font.descent
+            self.lines[0].paragraph_begin = self.lines[0].paragraph_end = True
             self.invalid_lines.invalidate(0, 1)

The next revision further changed tests/text/; the relevant log entries
for that file [from svn log tests/text/] are

r1873 | Alex.Holkner | 2008-03-06 01:22:23 -0800 (Thu, 06 Mar 2008) | 3 lines

Make EMPTY test less interactive

r1872 | Alex.Holkner | 2008-03-06 00:20:56 -0800 (Thu, 06 Mar 2008) | 3 lines

 Issue 241 : fix incremental layout of empty document.

Summary: exception during incremental layout of empty document
Sign in to add a comment

Powered by Google Project Hosting