I’ve been writing a custom snake game using python, pygame, and pyopengl. I’m trying to draw a shape on the screen. However, I’ve stumbled upon this error:
JavaScript
x
28
28
1
Traceback (most recent call last):
2
File "F:ProjectspythonPython_Gamevenvlibsite-packagesOpenGLlatebind.py", line 43, in __call__
3
return self._finalCall( *args, **named )
4
TypeError: 'NoneType' object is not callable
5
6
During handling of the above exception, another exception occurred:
7
8
Traceback (most recent call last):
9
File "F:ProjectspythonPython_Gamesrcgame.py", line 35, in <module>
10
main()
11
File "F:ProjectspythonPython_Gamesrcgame.py", line 31, in main
12
game.draw_shapes()
13
File "F:ProjectspythonPython_Gamesrcgame_classes.py", line 203, in draw_shapes
14
f.draw()
15
File "F:ProjectspythonPython_Gamesrcgame_classes.py", line 128, in draw
16
shape.draw()
17
File "F:ProjectspythonPython_Gamesrcopengl_classes.py", line 128, in draw
18
glVertex2fv(cosine, sine)
19
File "F:ProjectspythonPython_Gamevenvlibsite-packagesOpenGLlatebind.py", line 47, in __call__
20
return self._finalCall( *args, **named )
21
File "F:ProjectspythonPython_Gamevenvlibsite-packagesOpenGLwrapper.py", line 689, in wrapperCall
22
pyArgs = tuple( calculate_pyArgs( args ))
23
File "F:ProjectspythonPython_Gamevenvlibsite-packagesOpenGLwrapper.py", line 450, in calculate_pyArgs
24
yield converter(args[index], self, args)
25
File "F:ProjectspythonPython_Gamevenvlibsite-packagesOpenGLarraysarrayhelpers.py", line 115, in asArraySize
26
byteSize = handler.arrayByteCount( result )
27
AttributeError: ("'NumberHandler' object has no attribute 'arrayByteCount'", <function asArrayTypeSize.<locals>.asArraySize at 0x000002642A35DCA0>)
28
The console is throwing me a TypeError and an Attribute error. I’m not sure if this is due to my code or an issue with one of the libraries. I’m using Python 3.9.1, pygame 2.0.1, and PyOpenGL 3.1.5.
Here’s the snippet of my script where the issue arises:
JavaScript
1
21
21
1
class Circle:
2
def __init__(self, pivot: Point, radius: int, sides: int, fill: bool, color: Color):
3
self.pivot = pivot
4
self.radius = radius
5
self.sides = sides
6
self.fill = fill
7
self.color = color
8
9
# Draw the shape of the circle
10
def draw(self):
11
glColor3f(self.color.r, self.color.g, self.color.b)
12
if self.fill:
13
glBegin(GL_POLYGON)
14
else:
15
glBegin(GL_LINE_LOOP)
16
for i in range(100):
17
cosine = self.radius * cos(i*2*pi/self.sides) + self.pivot.x
18
sine = self.radius * sin(i*2*pi/self.sides) + self.pivot.y
19
glVertex2fv(cosine, sine)
20
glEnd()
21
Advertisement
Answer
The argument of glVertex2fv
must be an array with 2 elements. If you have two separate coordinates which are not aggregated in an array you must use glVertex2f
. See glVertex
:
glVertex2fv(cosine, sine)
JavaScript
1
2
1
glVertex2f(cosine, sine)
2