pygame-ce
pygame-ce copied to clipboard
Some lines drawn by `pygame.draw.line()` are being cut off or extended across a surface (3199)
Issue №3199 opened by Werxzy at 2022-05-28 11:53:01
Environment:
- Operating system : Windows 10
- Python version : 3.9.5
- SDL version : 2.0.18
- PyGame version : 2.1.2
Current behavior:
There's 2 cases I found where pygame.draw.line() is behaving incorrectly.
The first is similar to a past issue (# 2193) where the line is getting cut off early. Though in the example in the test code, reversing the points shows the correct result. The second is where the line is being extended across the surface, way passed where it should end. A similar line with a value changed by 1 can be drawn correctly.
Expected behavior:
The first case shouldn't be cut off and reversing the points should probably show the exact same result. The second case shouldn't extend that far.
Screenshots
Lines drawn incorrectly:

Lines with similar points drawn correctly:

Test code
import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
clock = pygame.time.Clock()
draw_set = True
a = (-100, -100)
b = (20, 200)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
draw_set = not draw_set
screen.fill('black')
if draw_set: # incorrect lines
pygame.draw.line(screen, 'red', a, b, 15)
pygame.draw.line(screen, 'blue', (-29, 131), (21, 106), 5)
else: # correct lines
pygame.draw.line(screen, 'red', b, a, 15) # reversed is fine
pygame.draw.line(screen, 'blue', (-29, 131), (20, 106), 5) # offset by 1, not extended
pygame.display.update()
clock.tick(60)
Comments
# # ankith26 commented at 2022-05-29 04:38:03
Hi, thanks for the bug report!
I can reproduce this issue in pygame 2.0.0 and pygame 2.1.2 (on windows 11) and I believe this issue exists in all 2.x releases.
A quick test with pygame 1.9.6 (after a few minor compat changes to your reproducer code) shows that this issue is a regression from 1.9.6 where changing draw_set did not visually affect the final output.
# # oddbookworm commented at 2022-11-29 03:42:59
Just reproduced on 2.1.3.dev8 on windows 11 with python 3.11
I tested it (with the code sample given by the first user) with pygame-ce 2.5.0 on Windows 11 and there is no bug, everything is drawn correctly on both cases.
Closing this issue as I can see the bug got fixed between 2 pygame-ce versions a long time ago.