@@ -872,6 +872,46 @@ def test_bezier(self):
872872 for posn in bg_test_points :
873873 self .check_at (surf , posn , bg_adjusted )
874874
875+ def test_no_pal_8bit_surf (self ):
876+ """
877+ Test that gfxdraw methods do not segfault when passed with no palette
878+ 8 bit surface.
879+ """
880+ s = pygame .Surface (
881+ size = (512 , 512 ), flags = 0 , depth = 8 , masks = (0xE0 , 0x1C , 0x03 , 0x00 )
882+ )
883+
884+ fg = (255 , 255 , 255 )
885+ points = [(10 , 10 ), (100 , 50 ), (50 , 100 )]
886+ for name , args in (
887+ ("pixel" , (s , 2 , 2 , fg )),
888+ ("hline" , (s , 5 , 50 , 10 , fg )),
889+ ("vline" , (s , 10 , 5 , 50 , fg )),
890+ ("line" , (s , 0 , 0 , 100 , 100 , fg )),
891+ ("rectangle" , (s , pygame .Rect (50 , 50 , 80 , 40 ), fg )),
892+ ("box" , (s , pygame .Rect (60 , 60 , 80 , 40 ), fg )),
893+ ("circle" , (s , 256 , 256 , 64 , fg )),
894+ ("aacircle" , (s , 256 , 256 , 64 , fg )),
895+ ("filled_circle" , (s , 256 , 256 , 32 , fg )),
896+ ("ellipse" , (s , 200 , 200 , 50 , 30 , fg )),
897+ ("aaellipse" , (s , 200 , 200 , 50 , 30 , fg )),
898+ ("filled_ellipse" , (s , 200 , 200 , 50 , 30 , fg )),
899+ ("arc" , (s , 256 , 256 , 60 , 0 , 180 , fg )),
900+ ("pie" , (s , 300 , 300 , 60 , 0 , 270 , fg )),
901+ ("trigon" , (s , 100 , 100 , 150 , 200 , 50 , 200 , fg )),
902+ ("aatrigon" , (s , 100 , 100 , 150 , 200 , 50 , 200 , fg )),
903+ ("filled_trigon" , (s , 100 , 100 , 150 , 200 , 50 , 200 , fg )),
904+ ("polygon" , (s , points , fg )),
905+ ("aapolygon" , (s , points , fg )),
906+ ("filled_polygon" , (s , points , fg )),
907+ ("textured_polygon" , (s , points , s , 0 , 0 )), # use same surface as texture
908+ ):
909+ try :
910+ func = getattr (pygame .gfxdraw , name )
911+ func (* args )
912+ except Exception as e :
913+ self .fail (f"gfxdraw.{ name } raised an exception: { e } " )
914+
875915
876916if __name__ == "__main__" :
877917 unittest .main ()
0 commit comments