简体   繁体   English

X Error of failed request: BadValue (integer parameter out of range for operation), PyOpenGL

[英]X Error of failed request: BadValue (integer parameter out of range for operation), PyOpenGL

I have this code:我有这个代码:

import pygame

from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *


vertices= (
    (1, -1, -1),
    (1, 1, -1),
    (-1, 1, -1),
    (-1, -1, -1),
    (1, -1, 1),
    (1, 1, 1),
    (-1, -1, 1),
    (-1, 1, 1)
    )

edges = ((0,1),(0,3),(0,4),(2,1),(2,3),(2,7),(6,3),(6,4),(6,7),(5,1),(5,4),(5,7))

surfaces = (
(0,1,2,3),
(3,2,7,6),
(6,7,5,4),
(4,5,1,0),
(1,5,7,2),
(4,0,3,6)
)


def Cube():

  glBegin(GL_QUADS)
  for surface in surfaces:
      x = 0
      for vertex in surface:
          x+=1
          glColor3fv(colors[x])
          glVertex3fv(verticies[vertex])
  glEnd()

  glBegin(GL_LINES)
  for edge in edges:
      for vertex in edge:
          glVertex3fv(verticies[vertex])
  glEnd()



def main():

  pygame.init()
  display = (800,600)
  pygame.display.set_mode(display, DOUBLEBUF|OPENGL)

  gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)

  glTranslatef(0.0,0.0, -5)

  while True:

      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              pygame.quit()
              quit()

      glRotatef(1, 3, 1, 1)
      glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
      Cube()
      pygame.display.flip()
      pygame.time.wait(10)



if __name__ == "__main__":

   main()

and this error:这个错误:

 X Error of failed request: BadValue (integer parameter out of range for operation) Major opcode of failed request: 154 (GLX) Minor opcode of failed request: 3 (X_GLXCreateContext) Value in failed request: 0x0 Serial number of failed request: 25 Current serial number in output stream: 26

I think these three lines have problem, actually line three, display mode:我觉得这三行有问题,其实是第三行,显示方式:

pygame.init()
display = (800,600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)

Only with this part of code in main function, I have the same problem.只有在 main 函数中使用这部分代码,我有同样的问题。 If I comment third line in main function I get, of course, error:如果我在 main 函数中注释第三行,我当然会得到错误:

Traceback (most recent call last): File "cube_0.py", line 66, in main() File "cube_0.py", line 60, in main pygame.display.flip() pygame.error: Display mode not set回溯(最后一次调用):文件“cube_0.py”,第 66 行,在 main() 文件“cube_0.py”,第 60 行,在 main pygame.display.flip() pygame.error: 未设置显示模式

See Pygame OpenGL init causes an X Error .请参阅Pygame OpenGL 初始化导致 X 错误 The issue has nothing to do with your code.该问题与您的代码无关。 It is causes by your system or graphics driver.这是由您的系统或图形驱动程序引起的。 Possibly you have to update pygame.可能你必须更新 pygame.

On Ubuntu 20.04 (uses bash), pygame.init() was giving me the above X Error.在 Ubuntu 20.04(使用 bash)上, pygame.init()给了我上面的 X 错误。 Putting the following in my ~/.bashrc solved it for me:将以下内容放入我的~/.bashrc为我解决了这个问题:

export SDL_VIDEODRIVER='dummy'

Note, also that my $DISPLAY environment variable is :0 One may thus also need the following in ~/.bashrc .请注意,我的$DISPLAY环境变量是:0因此可能还需要~/.bashrc中的以下内容。

export DISPLAY=:0

I was also running code from Pycharm, which required me to start pycharm.sh from a terminal session that already had the above environment variables initialized (it's a bug in Pycharm 2021).我还从 Pycharm 运行代码,这要求我从已经初始化上述环境变量的终端会话启动pycharm.sh (这是 Pycharm 2021 中的一个错误)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM