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

OverflowError: integer 32769 does not fit 'int16_t' #68

Closed
Duality4Y opened this issue Oct 4, 2016 · 6 comments · Fixed by #69
Closed

OverflowError: integer 32769 does not fit 'int16_t' #68

Duality4Y opened this issue Oct 4, 2016 · 6 comments · Fixed by #69

Comments

@Duality4Y
Copy link

i encountered this error/bug when running my pygame code.
i think it happens where a to big value for x is entered and can not be stored in a int16_t.
in my case it was a entity in my code going far offscreen.

this is the full traceback:
http://pastebin.com/hf1g75Fn

to reproduce:

>>> import pygame

>>> pygame.init()
(5, 0)

>>> screen = pygame.display.set_mode((300, 400))

>>> pygame.draw.circle(screen, (0xff, 0xff, 0xff), (((2**16)/2), 0), 1)
<rect(32767, 0, -32466, 2)>

>>> pygame.draw.circle(screen, (0xff, 0xff, 0xff), (((2**16)/2)+1, 0), 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/duality/.pyvenvs/pypyvenv/site-packages/pygame/draw.py", line 375, in circle
    _fillellipse(surface, pos, radius, radius, color)
  File "/home/duality/.pyvenvs/pypyvenv/site-packages/pygame/draw.py", line 587, in _fillellipse
    c_x - k, c_x + k - 1, c_y - h - 1)
  File "/home/duality/.pyvenvs/pypyvenv/site-packages/pygame/draw.py", line 127, in _drawhorizline
    sdlrect.x = start_x
OverflowError: integer 32768 does not fit 'int16_t'
integer 32768 does not fit 'int16_t'

>>>
@Duality4Y
Copy link
Author

ok did some research and found that in sdl 2.0 SDL_Rect fields are int type.
and that in sdl1.2 fields are Sint16_t.

@drnlm
Copy link
Member

drnlm commented Oct 4, 2016

pygame is clearly using a int32_t under the hood

>>> pygame.ver
'1.9.1release'
>>> pygame.draw.circle(screen, (0xff, 0xff, 0xff), (((2**31))-1, 0), 1)
<rect(2147483646, 0, 2, 1)>
>>> pygame.draw.circle(screen, (0xff, 0xff, 0xff), (((2**31)), 0), 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: signed integer is greater than maximum

We should do likewise .

@Duality4Y
Copy link
Author

Duality4Y commented Oct 10, 2016

seems i can make really big x y cordinates now. i have tested with 2**64, and 2**128
so this is pretty cool !

@Duality4Y
Copy link
Author

Duality4Y commented Oct 10, 2016

i noticed a curious thing though:

this:

>>> pygame.draw.circle(screen, (0xff, 0xff, 0xff), (10, 10), 1)
<rect(9, 9, 3, 3)>

and this:

>>> pygame.draw.circle(screen, (0xff, 0xff, 0xff), ((2**32) + 10, 20), 1)
<rect(4294967305, 19, 0, 3)>

and also this:

>>> pygame.draw.circle(screen, (0xff, 0x00, 0x00), ((2**16) + 10, 20), 1)
<rect(65545, 19, 0, 3)>

both draw the circle at x=10.
why is this?

@drnlm
Copy link
Member

drnlm commented Oct 10, 2016

Because the underlying C data type for the position is int16, everything gets truncated and you get these wrap-around effects. ygame has the same behaviour (try with 2**16 there),.

Because pygame uses an int32, while we use a python integer, pygame will oververflow on 2**32, while pygame-cffi won't.

@Duality4Y
Copy link
Author

alright, i guess it's not a to big issue, since who whould draw like that far out of the screen, when it's not necesarry.

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

Successfully merging a pull request may close this issue.

2 participants