Description
Environment:
- Operating system: Ubuntu 20.04 LTS
- Python version: 3.8.10
- SDL version: 2.28.5
- pygame-ce version: 2.4.0 (just installed from pip)
- Relevant hardware: -
Current behavior:
This issue has appeared in both original pygame and in pygame-ce.
I have a game in which some cars navigate the environment with obstacles using sensor data and they collide quite frequently with each other and with obstacles. The problem is that sometimes during collisions the program crashes. It throws Fatal Python error: Segmentation fault
but I'm 99% sure, that it's pygame. I use mask.overlap()
function to detect collisions and when I remove parts that use this function, the program works perfectly fine. What's interesting but very confusing is that the trace points to the blit()
function. Maybe I should also mention that I rotate the sprites using rotozoom()
and create masks from rotated images.
Expected behavior:
Pixel-perfect sprite collisions using mask.overlap()
without getting segmentation faults.
Steps to reproduce:
Create a number of moving sprites and check collisions between them using the mask.overlap()
function.
Unfortunately, I cannot easily provide an adequate path to reproduce the issue as I am not sure what really causes it (except that it's part of pygame). If you are really interested, I can provide the repo with the code of my program, but it also uses ROS2 and some of its additional packages so you will be required to download them. Then the steps to reproduce are:
- Launch the program
- Use arrows to move and collide with objects
- Try to collid with objects until it crashes
Stack trace/error output/other error logs
Fatal Python error: Segmentation fault
Current thread 0x00007f504d0a7740 (most recent call first):
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/python3.8/site-packages/gr_kinematic_sim/custom_utils/object_tools.py", line 71 in draw
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/python3.8/site-packages/gr_kinematic_sim/custom_utils/robots.py", line 103 in call_sensors
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/python3.8/site-packages/gr_kinematic_sim/custom_utils/robots.py", line 108 in draw
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/python3.8/site-packages/gr_kinematic_sim/custom_utils/gametools.py", line 141 in draw_every_sprite_in_list
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/python3.8/site-packages/gr_kinematic_sim/main.py", line 94 in main
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/gr_kinematic_sim/sim", line 11 in <module>
Fatal Python error: (pygame parachute) Segmentation Fault
Python runtime state: initialized
Current thread 0x00007f504d0a7740 (most recent call first):
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/python3.8/site-packages/gr_kinematic_sim/custom_utils/object_tools.py", line 71 in draw
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/python3.8/site-packages/gr_kinematic_sim/custom_utils/robots.py", line 103 in call_sensors
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/python3.8/site-packages/gr_kinematic_sim/custom_utils/robots.py", line 108 in draw
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/python3.8/site-packages/gr_kinematic_sim/custom_utils/gametools.py", line 141 in draw_every_sprite_in_list
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/python3.8/site-packages/gr_kinematic_sim/main.py", line 94 in main
File "/home/leev/workspaces/gr-kinematic-sim/install/gr_kinematic_sim/lib/gr_kinematic_sim/sim", line 11 in <module>
free(): invalid pointer
The mentioned draw()
function:
def draw(self):
rect_to_draw = copy(self.rect)
rect_to_draw.x += self.curr_offset_x
rect_to_draw.y += self.curr_offset_y
rotated_image = pygame.transform.rotozoom(self._original_image, self._current_rotation, 1)
self.screen.blit(rotated_image, rect_to_draw)