[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Another blitting surface to itself crash
I had a little play with the test_blit_to_self.py:
SDL VERSION:
1.2.13 prebuilts
PYGAME:
Mingw compiled, svn r 1619
OBSERVATIONS:
Unmodified the test wouldn't run at all as noted earlier.
I don't know if it's any help but I noticed after commenting out the "blitting screen to self" section that I could get the "blitting surface to self" test and "blitting surface to screen" to run the full 100 cycles if I instantiated the Surface `a` with pygame.SRCALPHA flags.
Also, if using BLEND_RGB_ADD flags "blitting screen to self" worked. Also screen.copy() worked as a source... but eh.
CONCLUSIONS:
s.blit(s, (0,0)) works if SRCALPHA bits set for s
screen.blit(screen, step, None, pygame.BLEND_RGB_ADD)
Is that any help for you guys in debugging?? I have no C-fu or I would have a tinker myself.
Cheers.
ps... attached modified version of test with "use alpha blit" changes
pps.
This is in surface.c around line 1996.... ??
/* see if we should handle alpha ourselves */
if (dst->format->Amask && (dst->flags & SDL_SRCALPHA) &&
!(src->format->Amask && !(src->flags & SDL_SRCALPHA)) &&
/* special case, SDL works */
(dst->format->BytesPerPixel == 2 || dst->format->BytesPerPixel == 4))
{
result = pygame_AlphaBlit (src, srcrect, dst, dstrect, the_args);
}
else if (the_args != 0)
{
result = pygame_Blit (src, srcrect, dst, dstrect, the_args);
}
else
{
result = SDL_BlitSurface (src, srcrect, dst, dstrect);
}
import pygame
import random
import math
import sys
print pygame.get_sdl_version()
# pygame.FULLSCREEN #create a fullscreen display
# pygame.DOUBLEBUF #recommended for HWSURFACE or OPENGL
# pygame.HWSURFACE #hardware accelerated, only in FULLSCREEN
# pygame.OPENGL #create an opengl renderable display
# pygame.RESIZABLE #display window should be sizeable
# pygame.NOFRAME #display window will have no border or controls
screen = pygame.display.set_mode((800, 600))
num_runs = 100
scroll_step = 100
for i in xrange(num_runs):
print "pass",i
test_width = random.randint(10,400)
test_height = random.randint(10,400)
# An optional special flags is for passing in new in 1.8.0: BLEND_ADD,
# BLEND_SUB, BLEND_MULT, BLEND_MIN, BLEND_MAX new in 1.8.1:
# BLEND_RGBA_ADD, BLEND_RGBA_SUB, BLEND_RGBA_MULT, BLEND_RGBA_MIN,
# BLEND_RGBA_MAX BLEND_RGB_ADD, BLEND_RGB_SUB, BLEND_RGB_MULT,
# BLEND_RGB_MIN, BLEND_RGB_MAX With other special blitting flags
# perhaps added in the future.
a = pygame.Surface((test_width, test_height), pygame.SRCALPHA)
a.fill((random.randint(0,255), random.randint(0,255), random.randint(0,255)))
try:
pygame.draw.line(a, (255,255,255), (0,0), (test_width, test_height), 10)
except:
pass
print "blitting surface to self"
sys.stdout.flush()
a.blit(a, (random.randint(-test_width, test_width), random.randint(-test_height, test_height)))
angle = (2.0*math.pi*i)/num_runs
step = (math.cos(angle)*scroll_step, math.sin(angle)*scroll_step)
print "blitting screen to self"
sys.stdout.flush()
screen.blit(screen, step, None, pygame.BLEND_RGB_ADD)
print "blitting surface to screen"
sys.stdout.flush()
screen.blit(a, (random.randint(-test_width, 800), random.randint(-test_height, 600)))
pygame.event.get()
pygame.display.flip()