pygame surface.blits when using area argument
我正在尝试使用带有area参数的surface.blits来提高代码的性能。当我使用blit的area参数时,遇到以下错误:
SystemError: <'method 'blits' of 'pygame.Surface' objects> returned a result with an error set.
如果我删除了area参数,blits会像我期望的那样工作。关于我可能做错了什么的任何想法?以下附件是我的用例和错误的示例代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import sys import random import pygame pygame.init() tilemap = pygame.image.load('pattern.jpg') tilesize = 64 size = 4 w, h = size*64, size*64 screen = pygame.display.set_mode((w, h)) while True: screen.fill((0, 0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() blit_list = [] for i in range(size): for j in range(size): xi, yi = random.randint(0, size), random.randint(0, size) blit_args = (tilemap, (i*tilesize, j*tilesize), (xi*tilesize, yi*tilesize, tilesize, tilesize)) # calling screen.blit here works correctly screen.blit(*blit_args) blit_list.append(blit_args) # instead of using multiple blit calls above, calling screen.blits here fails # remove the area argument (3rd arg) from each blit_arg tuple works # screen.blits(blit_list) pygame.display.flip() # wait a second pygame.time.wait(1000) |
这是我使用的图像(https://www.behance.net/gallery/19447645/Summer-patterns):
这是C代码中的错误。在surface.c第2258行中,对于
1 2 3 4 5 | if (dest->flags & SDL_OPENGL && !(dest->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL))) { bliterrornum = BLITS_ERR_NO_OPENGL_SURF; goto bliterror; } |
而在surface.c第2118行中,对于
1 2 3 4 5 6 | #if IS_SDLv1 if (dest->flags & SDL_OPENGL && !(dest->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL))) return RAISE(pgExc_SDLError, "Cannot blit to OPENGL Surfaces (OPENGLBLIT is ok)"); #endif /* IS_SDLv1 */ |
注意
问题似乎来自现在已不推荐使用的
Do not use the deprecated SDL_OPENGLBLIT mode which used to allow both blitting and using OpenGL. This flag is deprecated, for quite a few reasons. Under numerous circumstances, using SDL_OPENGLBLIT can corrupt your OpenGL state.
不幸的是,我不是OpenGL方面的专家,所以我无法进一步解释。希望有人可以发布更准确的答案。
我可以肯定的是,我可以在之前升高
这使我认为以上几行正在发生某些事情。
编辑
我可以确认是否在上述测试周围添加了
我在GitHub上提出了这个问题。