cledio66 / pyglet

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

Argument ewhen using PILImageDecoder #725

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Have you tried Pyglet 1.2 alpha1 or the repository code?
I am currently using the latest repository code as of a few days ago.  I tried 
searching for other reports on this but I haven

What steps will reproduce the problem?
1.
2.
3.

Paste in the traceback or error message:

Paste in the output of `python -m pyglet.info`:

Any additional info (platform/language/hardware) that may be relevant?

Original issue reported on code.google.com by timlag1...@gmail.com on 4 Apr 2014 at 3:02

GoogleCodeExporter commented 9 years ago
Sorry about that I accidentally prematurely posted this, the following should 
have been in the first post:

This is my first reported issue so please excuse me if I didn't provide the 
correct format or enough information.

Have you tried Pyglet 1.2 alpha1 or the repository code?

I am currently using the latest repository code as of a few days ago.  I tried 
searching for other reports on this but I haven't seen any solutions to my 
problem.  (I have been using the following method to import images because 
Image.load and resource.image wouldn't work for various reasons.)

What steps will reproduce the problem?
1. load image using: image.codecs.pil.PILImageDecoder().decode(open("path to 
file", "rb"), "filename")
2. create sprite from image using: pyglet.sprite.Sprite(img="loaded image 
name", x=0, y=0)

Paste in the traceback or error message:

Traceback (most recent call last):
    File "game.py", line 7, in <module>
        player_sprite = pyglet.sprite.Sprite(img=resources.player_image, x=400, y=300)
    File "/usr/local/lib/python3.3/site-packages/pyglet/sprite.py", line 234, in __init__
        self._texture = img.get_texture()
    File "/usr/local/lib/python3.3/site-packages/pyglet/image/__init__.py", line 817, in get_texture
        force_rectangle)
    File "/usr/local/lib/python3.3/site-packages/pyglet/image/__init__.py", line 808, in create_texture
        self.anchor_x, self.anchor_y, 0, None)
    File "/usr/local/lib/python3.3/site-packages/pyglet/image/__init__.py", line 982, in blit_to_texture
        glTexSubImage2D(target, level, x, y, self.width, self.height, format, type, data)
ctypes.ArgumentError: argument 3: <class 'TypeError'>: wrong type

Paste in the output of `python -m pyglet.info`:

Python
------------------------------------------------------------------------------
sys.version: 3.3.5 (default, Mar 14 2014, 01:23:44) 
[GCC 4.2.1 Compatible FreeBSD Clang 3.3 (tags/RELEASE_33/final 183502)]
sys.platform: freebsd10
sys.maxint: 9223372036854775807
os.getcwd(): /usr/home/tim/game

pyglet
------------------------------------------------------------------------------
pyglet.version: 1.2alpha1
pyglet.__file__: /usr/local/lib/python3.3/site-packages/pyglet/__init__.py
pyglet.options['font'] = ('gdiplus', 'win32')
pyglet.options['debug_trace_args'] = False
pyglet.options['xlib_fullscreen_override_redirect'] = False
pyglet.options['debug_trace'] = False
pyglet.options['debug_media'] = False
pyglet.options['debug_win32'] = False
pyglet.options['debug_trace_depth'] = 1
pyglet.options['graphics_vbo'] = True
pyglet.options['debug_trace_flush'] = True
pyglet.options['debug_graphics_batch'] = False
pyglet.options['debug_x11'] = False
pyglet.options['audio'] = ('directsound', 'pulse', 'openal', 'silent')
pyglet.options['debug_gl_trace_args'] = False
pyglet.options['darwin_cocoa'] = False
pyglet.options['shadow_window'] = True
pyglet.options['debug_lib'] = False
pyglet.options['debug_gl_trace'] = False
pyglet.options['xsync'] = True
pyglet.options['debug_gl'] = True
pyglet.options['search_local_libs'] = True
pyglet.options['debug_texture'] = False
pyglet.options['debug_font'] = False
pyglet.options['vsync'] = None

pyglet.window
------------------------------------------------------------------------------
platform: <pyglet.window.Platform object at 0x802005b50>
display: <pyglet.canvas.xlib.XlibDisplay object at 0x80777ee50>
screens[0]: XlibScreen(display=<pyglet.canvas.xlib.XlibDisplay object at 
0x80777ee50>, x=0, y=0, width=1280, height=1024, xinerama=0)
config['double_buffer'] = 1
config['stereo'] = 0
config['buffer_size'] = 24
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'] = 0
config['depth_size'] = 24
config['stencil_size'] = 0
config['accum_red_size'] = 0
config['accum_green_size'] = 0
config['accum_blue_size'] = 0
config['accum_alpha_size'] = 0
config['major_version'] = None
config['minor_version'] = None
config['forward_compatible'] = None
config['debug'] = None
context: XlibContext10()

window.context._info
------------------------------------------------------------------------------
gl_info.get_version(): 2.1 Mesa 7.6.1
gl_info.get_vendor(): Mesa Project
gl_info.get_renderer(): Software Rasterizer
gl_info.get_extensions():
    GL_3DFX_texture_compression_FXT1
    GL_APPLE_packed_pixels
    GL_APPLE_vertex_array_object
    GL_ARB_copy_buffer
    GL_ARB_depth_texture
    GL_ARB_draw_buffers
    GL_ARB_fragment_program
    GL_ARB_fragment_program_shadow
    GL_ARB_fragment_shader
    GL_ARB_framebuffer_object
    GL_ARB_half_float_pixel
    GL_ARB_imaging
    GL_ARB_map_buffer_range
    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_shading_language_120
    GL_ARB_shadow
    GL_ARB_shadow_ambient
    GL_ARB_sync
    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_mirrored_repeat
    GL_ARB_texture_non_power_of_two
    GL_ARB_texture_rectangle
    GL_ARB_transpose_matrix
    GL_ARB_vertex_array_bgra
    GL_ARB_vertex_array_object
    GL_ARB_vertex_buffer_object
    GL_ARB_vertex_program
    GL_ARB_vertex_shader
    GL_ARB_window_pos
    GL_ATI_blend_equation_separate
    GL_ATI_envmap_bumpmap
    GL_ATI_fragment_shader
    GL_ATI_separate_stencil
    GL_ATI_texture_env_combine3
    GL_ATI_texture_mirror_once
    GL_EXT_abgr
    GL_EXT_bgra
    GL_EXT_blend_color
    GL_EXT_blend_equation_separate
    GL_EXT_blend_func_separate
    GL_EXT_blend_logic_op
    GL_EXT_blend_minmax
    GL_EXT_blend_subtract
    GL_EXT_compiled_vertex_array
    GL_EXT_convolution
    GL_EXT_copy_texture
    GL_EXT_depth_bounds_test
    GL_EXT_draw_range_elements
    GL_EXT_fog_coord
    GL_EXT_framebuffer_blit
    GL_EXT_framebuffer_object
    GL_EXT_gpu_program_parameters
    GL_EXT_histogram
    GL_EXT_multi_draw_arrays
    GL_EXT_packed_depth_stencil
    GL_EXT_packed_pixels
    GL_EXT_paletted_texture
    GL_EXT_pixel_buffer_object
    GL_EXT_point_parameters
    GL_EXT_polygon_offset
    GL_EXT_provoking_vertex
    GL_EXT_rescale_normal
    GL_EXT_secondary_color
    GL_EXT_separate_specular_color
    GL_EXT_shadow_funcs
    GL_EXT_shared_texture_palette
    GL_EXT_stencil_two_side
    GL_EXT_stencil_wrap
    GL_EXT_subtexture
    GL_EXT_texture
    GL_EXT_texture3D
    GL_EXT_texture_edge_clamp
    GL_EXT_texture_env_add
    GL_EXT_texture_env_combine
    GL_EXT_texture_env_dot3
    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_swizzle
    GL_EXT_vertex_array
    GL_EXT_vertex_array_bgra
    GL_IBM_multimode_draw_arrays
    GL_IBM_rasterpos_clip
    GL_IBM_texture_mirrored_repeat
    GL_INGR_blend_func_separate
    GL_MESA_pack_invert
    GL_MESA_resize_buffers
    GL_MESA_texture_array
    GL_MESA_window_pos
    GL_MESA_ycbcr_texture
    GL_NV_blend_square
    GL_NV_fragment_program
    GL_NV_light_max_exponent
    GL_NV_point_sprite
    GL_NV_texgen_reflection
    GL_NV_texture_env_combine4
    GL_NV_texture_rectangle
    GL_NV_vertex_program
    GL_NV_vertex_program1_1
    GL_OES_read_format
    GL_SGIS_generate_mipmap
    GL_SGIS_texture_border_clamp
    GL_SGIS_texture_edge_clamp
    GL_SGIS_texture_lod
    GL_SGI_color_matrix
    GL_SGI_color_table
    GL_SGI_texture_color_table
    GL_SUN_multi_draw_arrays

pyglet.gl.glu_info
------------------------------------------------------------------------------
glu_info.get_version(): 1.3
glu_info.get_extensions():
    GLU_EXT_nurbs_tessellator
    GLU_EXT_object_space_tess

pyglet.gl.glx_info
------------------------------------------------------------------------------
context.is_direct(): 1
glx_info.get_server_vendor(): SGI
glx_info.get_server_version(): 1.2
glx_info.get_server_extensions():
    GLX_ARB_multisample
    GLX_EXT_visual_info
    GLX_EXT_visual_rating
    GLX_EXT_import_context
    GLX_EXT_texture_from_pixmap
    GLX_OML_swap_method
    GLX_SGI_make_current_read
    GLX_SGIS_multisample
    GLX_SGIX_hyperpipe
    GLX_SGIX_swap_barrier
    GLX_SGIX_fbconfig
    GLX_SGIX_pbuffer
    GLX_MESA_copy_sub_buffer
glx_info.get_client_vendor(): Mesa Project and SGI
glx_info.get_client_version(): 1.4
glx_info.get_client_extensions():
    GLX_ARB_get_proc_address
    GLX_ARB_multisample
    GLX_EXT_import_context
    GLX_EXT_visual_info
    GLX_EXT_visual_rating
    GLX_MESA_allocate_memory
    GLX_MESA_copy_sub_buffer
    GLX_MESA_swap_control
    GLX_MESA_swap_frame_usage
    GLX_OML_swap_method
    GLX_OML_sync_control
    GLX_SGI_make_current_read
    GLX_SGI_swap_control
    GLX_SGI_video_sync
    GLX_SGIS_multisample
    GLX_SGIX_fbconfig
    GLX_SGIX_pbuffer
    GLX_SGIX_visual_select_group
    GLX_EXT_texture_from_pixmap
glx_info.get_extensions():
    GLX_ARB_get_proc_address
    GLX_ARB_multisample
    GLX_EXT_import_context
    GLX_EXT_visual_info
    GLX_EXT_visual_rating
    GLX_OML_swap_method
    GLX_SGIS_multisample
    GLX_SGIX_fbconfig
    GLX_SGIX_pbuffer

pyglet.media
------------------------------------------------------------------------------
audio driver: <pyglet.media.drivers.silent.SilentAudioDriver object at 
0x807eb9a90>

pyglet.media.avbin
------------------------------------------------------------------------------
AVbin not available.

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

pyglet.input.wintab
------------------------------------------------------------------------------
WinTab not available.

Any additional info (platform/language/hardware) that may be relevant?

Platform: FreeBSD 10 64 bit, Python3.3

I fixed the error by editing line 981 of pyglet/image/__init__.py from:
    glTexSubImage2D(target, level, x, y, self.width, self.height, format, type, data)
to:
    glTexSubImage2D(target, level, int(x), int(y), self.width, self.height, format, type, data)

I am far from an experienced programmer so I don't know if this was the best 
way to fix the problem but I will leave that up to you guys.

Original comment by timlag1...@gmail.com on 4 Apr 2014 at 3:31

GoogleCodeExporter commented 9 years ago
FreeBSD is not a supported platform, we have a ticket to improve the situation, 
but it's not a priority.

See: https://code.google.com/p/pyglet/issues/detail?id=634

Original comment by useboxnet on 4 Apr 2014 at 7:30

GoogleCodeExporter commented 9 years ago
Alright, that's understandable.

Original comment by timlag1...@gmail.com on 4 Apr 2014 at 3:26

GoogleCodeExporter commented 9 years ago
While trying to reproduce I wrote a bugdemo:

#!/usr/bin/env python

import pyglet
from pyglet import image

window = pyglet.window.Window(640, 480)

@window.event
def on_draw():
    window.clear()
    sp.draw()

img = image.codecs.pil.PILImageDecoder().decode(open("ball.png", "rb"), 
"ball.png")
#img.anchor_x = 0.5
sp = pyglet.sprite.Sprite(img=img, x=400, y=300)

if __name__ == '__main__':
    pyglet.app.run()

It runs fine both with python 2.6.6 and 3.3.1

I think theres something more in the original situation, by example 
uncommenting the line that sets the anchor_x produces the same traceback as in 
the initial report.

Original comment by ccanepacc@gmail.com on 6 Apr 2014 at 6:34

Attachments:

GoogleCodeExporter commented 9 years ago
Right, I figured out the problem.  I forgot that in python 3, when you divide 
two integers (such as image.width / 2), the answer may come out as a floating 
point.  So that wasn't an API issue but a coding error on my part.

Original comment by timlag1...@gmail.com on 6 Apr 2014 at 7:29

GoogleCodeExporter commented 9 years ago
OK, anchor_x is expected to be an int:

http://pyglet.org/doc-current/api/pyglet/image/pyglet.image.AbstractImage.html#p
yglet.image.AbstractImage

The TypeError should be a clue, but I assumed it could be a platform issue.

Thanks for the report (and thanks Claudio for your help!).

Original comment by useboxnet on 17 Apr 2014 at 5:59