booglybob / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Exception when attributed text contains multiple trailing newlines #429

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Create a FormattedDocument from attributed text with multiple trailing
newlines. I would expect this to just generate empty paragraphs at the end.
The document appears to parse fine, but when setting it on an
IncrementalTextLayout, I get the following exception:

  File "C:\workspace\facewall\src\gui\wallmail_async.py", line 278, in <module>
    Window.run_camera(fps=20, display=False)
  File "C:\workspace\facewall\src\gui\__init__.py", line 116, in run_camera
    pyglet.app.run()
  File "C:\Python26\lib\site-packages\pyglet\app\__init__.py", line 264, in run
    EventLoop().run()
  File "C:\Python26\lib\site-packages\pyglet\app\win32.py", line 63, in run
    self._timer_func(0, 0, timer, 0)
  File "C:\Python26\lib\site-packages\pyglet\app\win32.py", line 84, in
_timer_func
    sleep_time = self.idle()
  File "C:\Python26\lib\site-packages\pyglet\app\__init__.py", line 187, in
idle
    dt = clock.tick(True)
  File "C:\Python26\lib\site-packages\pyglet\clock.py", line 706, in tick
    return _default.tick(poll)
  File "C:\Python26\lib\site-packages\pyglet\clock.py", line 298, in tick
    item.func(*item.args, **item.kwargs)
  File "C:\workspace\facewall\src\gui\wallmail_async.py", line 96, in
check_body_loaded
    self.box.document = doc
  File "C:\Python26\lib\site-packages\pyglet\text\layout.py", line 859, in
_set_document
    self._init_document()
  File "C:\Python26\lib\site-packages\pyglet\text\layout.py", line 1753, in
_init_document
    self.on_insert_text(0, self._document.text)
  File "C:\Python26\lib\site-packages\pyglet\text\layout.py", line 1779, in
on_insert_text
    self._update()
  File "C:\Python26\lib\site-packages\pyglet\text\layout.py", line 1838, in
_update
    self._update_flow_lines()
  File "C:\Python26\lib\site-packages\pyglet\text\layout.py", line 1978, in
_update_flow_lines
    invalid_end = self._flow_lines(self.lines, invalid_start, invalid_end)
  File "C:\Python26\lib\site-packages\pyglet\text\layout.py", line 1345, in
_flow_lines
    self._parse_distance(line_spacing_iterator[line.start])
  File "C:\Python26\lib\site-packages\pyglet\text\runlist.py", line 293, in
__getitem__
    self.start, self.end, self.value = self.next()
StopIteration

Using str.strip() to remove the trailing newlines from the original text
fixes the problem.

pyglet 1.1 with Python 2.5: Paste in the output of `python -m pyglet.info`
Other: Paste in the output of tools/gl_info.py (included in source distro):

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Program Files\Mozilla Firefox>python -m pyglet.info
Python
------------------------------------------------------------------------------
sys.version: 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
(Intel
)]
sys.platform: win32
os.getcwd(): C:\Program Files\Mozilla Firefox

pyglet
------------------------------------------------------------------------------
pyglet.version: 1.1.3
pyglet.__file__: C:\python26\lib\site-packages\pyglet\__init__.pyc
pyglet.options['debug_trace_depth'] = 1
pyglet.options['font'] = ('gdiplus', 'win32')
pyglet.options['xsync'] = True
pyglet.options['debug_trace_flush'] = True
pyglet.options['debug_win32'] = False
pyglet.options['debug_gl_trace'] = False
pyglet.options['debug_x11'] = False
pyglet.options['shadow_window'] = True
pyglet.options['debug_font'] = False
pyglet.options['debug_media'] = False
pyglet.options['debug_trace'] = False
pyglet.options['debug_lib'] = False
pyglet.options['graphics_vbo'] = True
pyglet.options['vsync'] = None
pyglet.options['debug_trace_args'] = False
pyglet.options['debug_gl'] = True
pyglet.options['debug_graphics_batch'] = False
pyglet.options['audio'] = ('directsound', 'openal', 'alsa', 'silent')
pyglet.options['debug_texture'] = False
pyglet.options['debug_gl_trace_args'] = False

pyglet.window
------------------------------------------------------------------------------
platform: <pyglet.window.win32.Win32Platform object at 0x00E5A2D0>
display: <pyglet.window.win32.Win32Display object at 0x00E5A250>
screens[0]: Win32Screen(x=0, y=0, width=1600, height=1200)
screens[1]: Win32Screen(x=-1280, y=0, width=1280, height=1024)
config['double_buffer'] = True
config['stereo'] = False
config['buffer_size'] = 32
config['aux_buffers'] = 0
config['sample_buffers'] = 0
config['samples'] = 0
config['red_size'] = 8
config['green_size'] = 8
config['blue_size'] = 8
config['alpha_size'] = 8
config['depth_size'] = 24
config['stencil_size'] = 8
config['accum_red_size'] = 0
config['accum_green_size'] = 0
config['accum_blue_size'] = 0
config['accum_alpha_size'] = 0
context: Win32Context()

pyglet.gl.gl_info
------------------------------------------------------------------------------
gl_info.get_version(): 2.1.7769 Release
gl_info.get_vendor(): ATI Technologies Inc.
gl_info.get_renderer(): ATI Radeon HD 2400 Pro
gl_info.get_extensions():
   GL_AMD_performance_monitor
   GL_ARB_color_buffer_float
   GL_ARB_depth_texture
   GL_ARB_draw_buffers
   GL_ARB_fragment_program
   GL_ARB_fragment_shader
   GL_ARB_multisample
   GL_ARB_multitexture
   GL_ARB_occlusion_query
   GL_ARB_pixel_buffer_object
   GL_ARB_point_parameters
   GL_ARB_point_sprite
   GL_ARB_shader_objects
   GL_ARB_shading_language_100
   GL_ARB_shadow
   GL_ARB_shadow_ambient
   GL_ARB_texture_border_clamp
   GL_ARB_texture_compression
   GL_ARB_texture_cube_map
   GL_ARB_texture_env_add
   GL_ARB_texture_env_combine
   GL_ARB_texture_env_crossbar
   GL_ARB_texture_env_dot3
   GL_ARB_texture_float
   GL_ARB_texture_mirrored_repeat
   GL_ARB_texture_non_power_of_two
   GL_ARB_texture_rectangle
   GL_ARB_transpose_matrix
   GL_ARB_vertex_buffer_object
   GL_ARB_vertex_program
   GL_ARB_vertex_shader
   GL_ARB_window_pos
   GL_ATI_draw_buffers
   GL_ATI_envmap_bumpmap
   GL_ATI_fragment_shader
   GL_ATI_meminfo
   GL_ATI_separate_stencil
   GL_ATI_shader_texture_lod
   GL_ATI_texture_compression_3dc
   GL_ATI_texture_env_combine3
   GL_ATI_texture_float
   GL_EXT_abgr
   GL_EXT_bgra
   GL_EXT_blend_color
   GL_EXT_blend_func_separate
   GL_EXT_blend_minmax
   GL_EXT_blend_subtract
   GL_EXT_compiled_vertex_array
   GL_EXT_copy_texture
   GL_EXT_draw_range_elements
   GL_EXT_fog_coord
   GL_EXT_framebuffer_blit
   GL_EXT_framebuffer_multisample
   GL_EXT_framebuffer_object
   GL_EXT_framebuffer_sRGB
   GL_EXT_gpu_program_parameters
   GL_EXT_multi_draw_arrays
   GL_EXT_packed_depth_stencil
   GL_EXT_packed_float
   GL_EXT_packed_pixels
   GL_EXT_point_parameters
   GL_EXT_rescale_normal
   GL_EXT_secondary_color
   GL_EXT_separate_specular_color
   GL_EXT_shadow_funcs
   GL_EXT_stencil_wrap
   GL_EXT_subtexture
   GL_EXT_texgen_reflection
   GL_EXT_texture3D
   GL_EXT_texture_compression_s3tc
   GL_EXT_texture_cube_map
   GL_EXT_texture_edge_clamp
   GL_EXT_texture_env_add
   GL_EXT_texture_env_combine
   GL_EXT_texture_env_dot3
   GL_EXT_texture_filter_anisotropic
   GL_EXT_texture_lod_bias
   GL_EXT_texture_mirror_clamp
   GL_EXT_texture_object
   GL_EXT_texture_rectangle
   GL_EXT_texture_sRGB
   GL_EXT_texture_shared_exponent
   GL_EXT_vertex_array
   GL_KTX_buffer_region
   GL_NV_blend_square
   GL_NV_texgen_reflection
   GL_SGIS_generate_mipmap
   GL_SGIS_texture_edge_clamp
   GL_SGIS_texture_lod
   GL_WIN_swap_hint
   WGL_EXT_swap_control

pyglet.gl.glu_info
------------------------------------------------------------------------------
glu_info.get_version(): 1.2.2.0 Microsoft Corporation
glu_info.get_extensions():
   GL_EXT_bgra

pyglet.gl.glx_info
------------------------------------------------------------------------------
GLX not available.

pyglet.media
------------------------------------------------------------------------------
driver: pyglet.media.drivers.directsound

pyglet.media.avbin
------------------------------------------------------------------------------
Library: <CDLL 'avbin', handle 6e440000 at f963d0>
AVbin version: 5
FFmpeg revision: 13661

pyglet.media.drivers.openal
------------------------------------------------------------------------------
OpenAL not available.

Original issue reported on code.google.com by ChrisM6794@gmail.com on 6 Jul 2009 at 5:54

GoogleCodeExporter commented 8 years ago
I'm having trouble reproducing the bug - the following code runs just fine 
under both SVN trunk and 1.1.3:

import pyglet

doc = pyglet.text.decode_attributed('{bold True}Hello{bold False}\n\n\n\n')
doc2 = pyglet.text.decode_attributed('{bold True}Goodbye{bold False}\n\n\n\n')
layout = pyglet.text.layout.IncrementalTextLayout(doc, 100, 10)
layout.document = doc2

Original comment by m.e.w.ol...@gmail.com on 14 Aug 2009 at 1:31

GoogleCodeExporter commented 8 years ago
Your code sample works for me too; I am having a hard time getting a simpler 
sample
case that still breaks. Since strip() inexplicably works it's not a big problem 
for
me... I'll come back to it if I get the time.

Original comment by ChrisM6794@gmail.com on 14 Aug 2009 at 3:55

GoogleCodeExporter commented 8 years ago
Any code that demonstrates the bug is better than none, even if it is your 
whole program. Feel free to email if 
you don't want to attach it publically. The obvious @gmail.com

Original comment by m.e.w.ol...@gmail.com on 14 Aug 2009 at 4:10

GoogleCodeExporter commented 8 years ago
Here's a variant of that code sample which generates a similar traceback for me:

import pyglet

doc = pyglet.text.decode_attributed('{bold True}Hello{bold False}\n\n\n\n')
doc2 = pyglet.text.decode_attributed('{bold True}Goodbye{bold False}\n\n\n\n')
layout = pyglet.text.layout.IncrementalTextLayout(doc, 100, 10)
layout.document = doc2
layout.document.delete_text(0, len(layout.document.text))

This is using pyglet 1.2dev (the current hg head) on Mac OS 10.6.3, using Python
2.6.2 installed from python.org. (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 think the real issue isn't the document replacement or the newlines, but 
deleting
all text when there are mixed font styles, since the following simpler example 
also
gives a similar traceback:

import pyglet
doc2 = pyglet.text.decode_attributed('{bold True}a{bold False}b')
layout = pyglet.text.layout.IncrementalTextLayout(doc2, 100, 10)
layout.document.delete_text(0, len(layout.document.text))

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/p
yglet/text/document.py",
line 445, in delete_text
    self.dispatch_event('on_delete_text', start, end)
  File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/p
yglet/event.py",
line 340, in dispatch_event
    if handler(*args):
  File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/p
yglet/text/layout.py",
line 1804, in on_delete_text
    self._update()
  File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/p
yglet/text/layout.py",
line 1837, in _update
    font = self.document.get_font(0, dpi=self._dpi)
  File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/p
yglet/text/document.py",
line 660, in get_font
    return iter[position]
  File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/p
yglet/text/document.py",
line 719, in __getitem__
    font_name, font_size, bold, italic = self.zip_iter[index]
  File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/p
yglet/text/runlist.py",
line 403, in __getitem__
    return [i[index] for i in self.range_iterators]
  File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/p
yglet/text/runlist.py",
line 293, in __getitem__
    self.start, self.end, self.value = self.next()
StopIteration

A possible clue to the cause (but no guarantee, since it's different code): in a
larger editor example (not posted here), doing the same thing manually gets a 
similar
traceback, and a subsequent click in the text widget gets the following 
additional
traceback:

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 295, in 'calling callback function'
  File "/Applications/pyglet/pyglet-hg/pyglet/window/carbon/__init__.py", line 797,
in _on_mouse_down
    self.dispatch_event('on_mouse_press', x, y, button, modifiers)
  File "/Applications/pyglet/pyglet-hg/pyglet/window/__init__.py", line 1150, in
dispatch_event
    if EventDispatcher.dispatch_event(self, *args) != False:
  File "/Applications/pyglet/pyglet-hg/pyglet/event.py", line 369, in dispatch_event
    event_type, args, getattr(self, event_type))
  File "/Applications/pyglet/pyglet-hg/pyglet/event.py", line 365, in dispatch_event
    if getattr(self, event_type)(*args):
  File "edithack1.py", line 363, in on_mouse_press
    self.focus.caret.on_mouse_press(x, y, button, modifiers)
  File "/Applications/pyglet/pyglet-hg/pyglet/text/caret.py", line 552, in on_mouse_press
    self.move_to_point(x, y)
  File "/Applications/pyglet/pyglet-hg/pyglet/text/caret.py", line 322, in move_to_point
    line = self._layout.get_line_from_point(x, y)
  File "/Applications/pyglet/pyglet-hg/pyglet/text/layout.py", line 2272, in
get_line_from_point
    if y > line.y + line.descent:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

(Since this provides a repeatable example, I'm unblocking the bug. I'm also 
revising
the summary to fit my guess about the true cause.)

Original comment by ores...@gmail.com on 27 Apr 2010 at 6:46

GoogleCodeExporter commented 8 years ago
Oops, I acted too fact -- it looks like the problem I posted is a duplicate of 
open
issue 471 (which is itself a duplicate of improperly closed issue 241). Also, 
the
traceback I posted ends similarly to the original traceback, but doesn't look 
similar
at intermediate points, so it may or may not be the same bug. 

I will reopen issue 241, officially mark issue 471 as a duplicate of issue 241, 
and
post my new info into issue 241. I'll change this issue's status and summary 
(well, I
can't figure out how to find the old summary!) back to what they were 
originally, and
let this issue's owner decide what to do further on it.

Original comment by ores...@gmail.com on 27 Apr 2010 at 7:00

GoogleCodeExporter commented 8 years ago
(FYI, I ended up leaving issue 241 closed and not marking issue 471 as a 
duplicate of
it -- see their comments for details. It is still quite possible that this 
issue,
whatever it is, will be fixed when 471 is fixed.)

Original comment by ores...@gmail.com on 27 Apr 2010 at 10:33

GoogleCodeExporter commented 8 years ago
This issue was closed by revision dd518f80b6e3.

Original comment by useboxnet on 17 Jul 2013 at 7:47

GoogleCodeExporter commented 8 years ago
I backported the fix from default:

http://code.google.com/p/pyglet/source/detail?r=dd518f80b6e3ffe5846189dbc647af66
3ce7e5aa&name=pyglet-1.1-maintenance

Original comment by useboxnet on 17 Jul 2013 at 7:52