Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault in example aliens script if ran in loop #2543

Closed
ghost opened this issue Mar 30, 2021 · 7 comments
Closed

Segfault in example aliens script if ran in loop #2543

ghost opened this issue Mar 30, 2021 · 7 comments
Labels
bug font pygame.font

Comments

@ghost
Copy link

ghost commented Mar 30, 2021

Environment:

You can get some of this info from the text that pops up in the console when you run a pygame program.

  • Operating system (e.g. Windows, Linux(Debian), Linux(Ubuntu), Mac): MacOS 11.2.3
  • Python version (e.g. 3.7.9, 3.8.5) : 3.9.2
  • SDL version (e.g. SDL 2.0.12): 2.0.14
  • PyGame version (e.g. 2.0.0.dev10, 1.9.6): 2.0.1
  • Relevant hardware (e.g. if reporting a bug about a controller, tell us the brand & name of it):

Current behavior:

After ~5 minutes of playing, python will give
zsh: segmentation fault python3 -m pygame.examples.aliens

Expected behavior:

The game does not segfault

Screenshots

If applicable, copy and paste screenshots to help explain your problem.

Steps to reproduce:

  1. Download pygame
  2. Apply the change from https://github.com/pygame/pygame/compare/main...Pycryptor10:patch-1.diff
  3. run python3 -m pygame.examples.aliens
  4. Keep playing for ~5 minutes

Test code

https://github.com/pygame/pygame/compare/main...Pycryptor10:patch-1.diff

Stack trace/error output/other error logs
See files attached to https://bugs.python.org/issue43671 as I thought it could be a python issue first

@ghost ghost added the bug label Mar 30, 2021
@ghost
Copy link
Author

ghost commented Mar 30, 2021

Call to __init__ on line 142 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/examples/aliens.py from line 384 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/examples/aliens.py
Call to __init__ on line 112 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py from line 143 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/examples/aliens.py
Call to add on line 117 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py from line 115 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py
Call to add on line 117 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py from line 133 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py
Call to add_internal on line 373 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py from line 130 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py
Call to add_internal on line 153 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py from line 131 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py
Call to add_internal on line 373 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py from line 130 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py
Call to add_internal on line 153 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py from line 131 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py
Call to add_internal on line 1351 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py from line 130 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py
zsh: segmentation fault  python3 -m pygame.examples.aliens

is last part executed pre crash

@ghost
Copy link
Author

ghost commented Mar 30, 2021

Call to __init__ on line 218 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/examples/aliens.py from line 389 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/examples/aliens.py
Call to __init__ on line 112 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py from line 219 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/examples/aliens.py
Call to add on line 117 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py from line 115 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py
Call to add on line 117 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py from line 133 of /Users/cern/vevns/epq2/lib/python3.9/site-packages/pygame/sprite.py
zsh: segmentation fault  python3 -m pygame.examples.aliens

another

@ghost
Copy link
Author

ghost commented Mar 30, 2021

I did some more testing and replaced https://github.com/Pycryptor10/pygame/blob/patch-1/src_py/sprite.py#L117-L133 with

def add(self, *groups):
        """add the sprite to groups

        Sprite.add(*groups): return None

        Any number of Group instances can be passed as arguments. The
        Sprite will be added to the Groups it is not already a member of.

        """
        print("call to line 117, reached 126")
        has = self.__g.__contains__
        print("dumping has")
        for attr in dir(has):
            print("obj.%s = %r" % (attr, getattr(has, attr)))
        print("dumped")
        for group in groups:
            if hasattr(group, '_spritegroup'):
                if not has(group):
                    group.add_internal(self)
                    self.add_internal(group)
            else:
                self.add(*group)

but I never saw it get past: print("call to line 117, reached 126") when that was been ran. (It did on my next run when I added code to dump self.__g but I'm not really sure now what to do).

@ghost
Copy link
Author

ghost commented Mar 30, 2021

As far as I can confidently see is that the segfault happens within https://github.com/pygame/pygame/blob/main/src_py/sprite.py#L117-L133. Not sure beyond that.

@ghost
Copy link
Author

ghost commented Mar 31, 2021

aliens.py(393):         for alien in pg.sprite.spritecollide(player, aliens, 1):
 --- modulename: sprite, funcname: spritecollide
sprite.py(1655):     default_sprite_collide_func = sprite.rect.colliderect
sprite.py(1657):     if dokill:
sprite.py(1659):         crashed = []
sprite.py(1660):         append = crashed.append
sprite.py(1662):         for group_sprite in group.sprites():
 --- modulename: sprite, funcname: sprites
sprite.py(381):         return list(self.spritedict)
Fatal Python error: Segmentation fault

is last thing given when running python with --trace

That matches to https://github.com/pygame/pygame/blob/main/src_py/sprite.py#L371 because of my debug code

@Starbuck5
Copy link
Contributor

If REW1L is correct about the cause of this issue, which I am inclined to think they are, this is not a mac specific issue, and can be reproduced with

import pygame
import gc
 
pygame.font.init()
font = pygame.font.Font(None, 20)
pygame.font.quit()
pygame.font.init()
del font
gc.collect()
print('hey') # never reached

@Starbuck5 Starbuck5 added font pygame.font and removed Platform: MacOS labels Aug 20, 2021
illume added a commit that referenced this issue Oct 23, 2021
Fix issue #2543 segfault in font dealloc after reinit
@ankith26
Copy link
Contributor

I cannot seem to reproduce this segfault in the latest version which has the font segfault fix PR merged, so this issue is fixed by that as well (please re-open if you can still reproduce this :) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug font pygame.font
Projects
None yet
Development

No branches or pull requests

3 participants