Re: [pygame] BUG: segfault when blitting surface to itself

2008-04-12 Thread claxo


On 11 Apr 2008 at 21:33, Marcus von Appen wrote:

Is there some case where blitting a surface on itself might be 
desired
or necessary? If not, I'll add a simple check that tests the passed
surface on equality and let blit() throw an exception, if both are 
the same.

Its also used by effects, as you can see at:
http://www.pygame.org/pcr/meltdown/index.php

And older games in pygame ( linki commes to mind, first release of 
magicor also, I fixed the last for that problem) also used them.

claxo


Re: [pygame] BUG: segfault when blitting surface to itself

2008-04-11 Thread Brian Fisher
On Fri, Apr 11, 2008 at 12:33 PM, Marcus von Appen <[EMAIL PROTECTED]> wrote:
>  Is there some case where blitting a surface on itself might be desired
>  or necessary? If not, I'll add a simple check that tests the passed
>  surface on equality and let blit() throw an exception, if both are the
>  same.
>
That sounds great. This has come up multiple times on the list over
the years, and it would be good if it didn't. As a cross-platform
library, pygame should really be stopping users from doing things on
one platform that can't work on other platforms, to encourage writing
portable code.


Re: [pygame] BUG: segfault when blitting surface to itself

2008-04-11 Thread Greg Ewing

Marcus von Appen wrote:


Is there some case where blitting a surface on itself might be desired
or necessary?


Scrolling?

--
Greg


Re: [pygame] BUG: segfault when blitting surface to itself

2008-04-11 Thread Casey Duncan

On Apr 11, 2008, at 3:46 PM, David Muffley wrote:

Is there some case where blitting a surface on itself might be desired
or necessary? If not, I'll add a simple check that tests the passed
surface on equality and let blit() throw an exception, if both are the
same.

Regards
Marcus

For scrolling (topdown RPG, in my case), I use a surface just larger  
than the screen to hold all my unmoving objects, tiles, trees,  
chests, etc, and keep a Rect for where to put that surface onto the  
screen.  Whenever I move a tiles worth in any direction (lets say i  
move 32 pixels to the right), I need to blit the rect <32, 0, width,  
height> to <0, 0, width, height> and add the rightmost-visible tiles  
to it.  My first idea was to blit the surface onto itself, but of  
course that blew up on me.


My fix was to use two surfaces and just blit from one onto the  
other, switching between the two every time I need to add another  
row/column onto the screen.  It's not really memory inefficient (I  
only keep one extra 672x512 surface and a pointer in memory), but it  
definitely wasn't straightforward, and took me a while longer than I  
expected to implement it. Blitting a surface onto itself would have  
been much simpler.


Yeah, certainly "scrolling" is a general use-case for blitting a  
surface onto itself. I could also imagine some forms of composing with  
alpha channels. Both of these can certainly be done with two surfaces  
instead, but a self-blit would be more efficient.


-Casey



Re: [pygame] BUG: segfault when blitting surface to itself

2008-04-11 Thread David Muffley
>
> Is there some case where blitting a surface on itself might be desired
> or necessary? If not, I'll add a simple check that tests the passed
> surface on equality and let blit() throw an exception, if both are the
> same.
>
> Regards
> Marcus


For scrolling (topdown RPG, in my case), I use a surface just larger than
the screen to hold all my unmoving objects, tiles, trees, chests, etc, and
keep a Rect for where to put that surface onto the screen.  Whenever I move
a tiles worth in any direction (lets say i move 32 pixels to the right), I
need to blit the rect <32, 0, width, height> to <0, 0, width, height> and
add the rightmost-visible tiles to it.  My first idea was to blit the
surface onto itself, but of course that blew up on me.

My fix was to use two surfaces and just blit from one onto the other,
switching between the two every time I need to add another row/column onto
the screen.  It's not really memory inefficient (I only keep one extra
672x512 surface and a pointer in memory), but it definitely wasn't
straightforward, and took me a while longer than I expected to implement it.
Blitting a surface onto itself would have been much simpler.


Re: [pygame] BUG: segfault when blitting surface to itself

2008-04-11 Thread Hugo Arts
On Fri, Apr 11, 2008 at 8:33 PM, Marcus von Appen <[EMAIL PROTECTED]> wrote:

> On, Fri Apr 11, 2008, Hugo Arts wrote:
>
> > python version: 2.5.1
> > pygame version: 1.8
> > OS: Windows XP
> >
> > If you attempt to blit a surface to itself, python segfaults. Seems to
> occur
> > only on windows (tested on XP and Ubuntu).
> > I understand there is no reason to do this, but it would seem more
> > appropriate to throw an exception or something like that.
> >
> > script to reproduce:
> > import pygame
> > pygame.init()
> >
> > a = pygame.Surface((10, 10))
> > a.blit(a, (0, 0))
>
> Is there some case where blitting a surface on itself might be desired
> or necessary? If not, I'll add a simple check that tests the passed
> surface on equality and let blit() throw an exception, if both are the
> same.
>
> Regards
> Marcus
>

I can't think of a reason to blit a sprite onto itself. And if you really
want to,
you could create a copy of the surface, and blit with that (though it would
be less memory efficient).

Hugo


Re: [pygame] BUG: segfault when blitting surface to itself

2008-04-11 Thread Marcus von Appen
On, Fri Apr 11, 2008, Hugo Arts wrote:

> python version: 2.5.1
> pygame version: 1.8
> OS: Windows XP
> 
> If you attempt to blit a surface to itself, python segfaults. Seems to occur
> only on windows (tested on XP and Ubuntu).
> I understand there is no reason to do this, but it would seem more
> appropriate to throw an exception or something like that.
> 
> script to reproduce:
> import pygame
> pygame.init()
> 
> a = pygame.Surface((10, 10))
> a.blit(a, (0, 0))

Is there some case where blitting a surface on itself might be desired
or necessary? If not, I'll add a simple check that tests the passed
surface on equality and let blit() throw an exception, if both are the
same.

Regards
Marcus


pgpispUNtqcQj.pgp
Description: PGP signature


[pygame] BUG: segfault when blitting surface to itself

2008-04-11 Thread Hugo Arts
python version: 2.5.1
pygame version: 1.8
OS: Windows XP

If you attempt to blit a surface to itself, python segfaults. Seems to occur
only on windows (tested on XP and Ubuntu).
I understand there is no reason to do this, but it would seem more
appropriate to throw an exception or something like that.

script to reproduce:
import pygame
pygame.init()

a = pygame.Surface((10, 10))
a.blit(a, (0, 0))

Output:
Fatal Python error: (pygame parachute) Segmentation Fault

This application has requested the Runtime to terminate it in an unusual
way.
Please contact the application's support team for more information.