I'm trying to get started with pysdl2 on a windows machine. So far I have just got as far as copying-and-pasting the Hello World tutorial, just so I can see if it's actually working! It isn't.
import sys
import sdl2.ext
RESOURCES = sdl2.ext.Resources(__file__, "resources")
sdl2.ext.init()
window = sdl2.ext.Window("Hello World!", size=(640, 580))
window.show()
factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
sprite = factory.from_image(RESOURCES.get_path("testimage.png"))
spriterenderer = factory.create_sprite_render_system(window)
spriterenderer.render(sprite)
processor = sdl2.ext.TestEventProcessor()
processor.run(window)
sdl2.ext.quit()
When I run the program, it briefly displays a window then crashes with this error:
Traceback (most recent call last):
File "test.py", line 15, in <module>
spriterenderer.render(sprite)
File "C:\Python27\lib\site-packages\sdl2\ext\sprite.py", line 643, in render
surface.SDL_BlitSurface(sprites.surface, None, self.surface, r)
WindowsError: exception: access violation reading 0x03F3B000
although the address is different each time.
This only seems to happen on larger images - if I resize the image to 245 x 245
pixels or smaller, then it will display without complaint. I'm using Pillow for improved format support and get the same problem with bmp
, png
and jpg
.
Edited to add:
Today, I've been poking at this again trying to understand. My test image that was 245x245
pixels wouldn't work any more, unless I did something between creating the spriterenderer and calling render(sprite)
on it - I added print sprite
between those lines out of interest to see if there was actually something in the variable and there is, and it displays. Comment out the print
line and it fails. Then I made the same image larger, 500x500
and got the access violation
error again. I have no idea what it going on.