Python arcade draw_text 奇怪报错

我在写一个python arcade库的游戏时,有多个窗口。(开始界面,不同关)
在有一些窗口里面,我用了 draw_text 方法。
但是第二次打开新窗口时,会出现玄学报错

Traceback (most recent call last):
  File "c:/Users/Lucas/Desktop/test.py", line 25, in <module>
    run()
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\arcade\window_commands.py", line 226, in run
    pyglet.app.run()
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\app\__init__.py", line 107, in run   
    event_loop.run()
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\app\base.py", line 167, in run       
    timeout = self.idle()
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\app\base.py", line 243, in idle      
    window.dispatch_event('on_draw')
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\window\__init__.py", line 1333, in dispatch_event
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\event.py", line 415, in dispatch_event
    if getattr(self, event_type)(*args):
  File "c:/Users/Lucas/Desktop/test.py", line 19, in on_draw
    draw_text("test", 100, 100, arcade.color.RED)
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\arcade\text.py", line 325, in draw_text
    label.text_sprite_list.draw()
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\arcade\sprite_list.py", line 965, in draw
    self.program['Texture'] = self.texture_id
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\arcade\gl\program.py", line 201, in __setitem__
    uniform.setter(value)
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\arcade\gl\uniform.py", line 145, in setter_func
    gl_setter(location, count, ptr)
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\gl\lib.py", line 107, in errcheck
    raise GLException(msg)
pyglet.gl.lib.GLException: b'\xce\xde\xd0\xa7\xb2\xd9\xd7\xf7'
PS C:\Users\Lucas> & C:/Users/Lucas/AppData/Local/Programs/Python/Python37/python.exe c:/Users/Lucas/Desktop/test.py
Traceback (most recent call last):
  File "c:/Users/Lucas/Desktop/test.py", line 28, in <module>
    arcade.run()
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\arcade\window_commands.py", line 226, in run
    pyglet.app.run()
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\app\__init__.py", line 107, in run
    event_loop.run()
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\app\base.py", line 167, in run
    timeout = self.idle()
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\app\base.py", line 243, in idle
    window.dispatch_event('on_draw')
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\window\__init__.py", line 1333, in dispatch_event
    if EventDispatcher.dispatch_event(self, *args) != False:
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\event.py", line 415, in dispatch_event
    if getattr(self, event_type)(*args):
  File "c:/Users/Lucas/Desktop/test.py", line 20, in on_draw
    arcade.draw_text("test", 100, 100, arcade.color.RED) # 就是这里出错,删掉就好了
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\arcade\text.py", line 325, in draw_text
    label.text_sprite_list.draw()
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\arcade\sprite_list.py", line 965, in draw
    self.program['Texture'] = self.texture_id
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\arcade\gl\program.py", line 201, in __setitem__
    uniform.setter(value)
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\arcade\gl\uniform.py", line 145, in setter_func
    gl_setter(location, count, ptr)
  File "C:\Users\Lucas\AppData\Local\Programs\Python\Python37\lib\site-packages\pyglet\gl\lib.py", line 107, in errcheck
    raise GLException(msg)
pyglet.gl.lib.GLException: b'\xce\xde\xd0\xa7\xb2\xd9\xd7\xf7'
#测试简化代码(删掉draw_text就一切正常)
import arcade

class Test1(arcade.Window):
    def __init__(self):
        super().__init__(800, 600) # 创建窗口

    def on_draw(self):
        arcade.start_render()

    def on_key_press(self, symbol: int, modifiers: int):
        Test2() # 切换窗口
        self.__del__()  

class Test2(arcade.Window):
    def __init__(self):
        super().__init__(800,600) # 创建窗口

    def on_draw(self):
        arcade.start_render()
        arcade.draw_text("test", 100, 100, arcade.color.RED) # 就是这里出错,删掉就好了


    def on_key_press(self, symbol: int, modifiers: int):
        Test1() # 切换窗口
        self.__del__()

Test1()
arcade.run() 

大佬帮一下吧。

可能是draw_text触发on_draw事件,导致循环调用了,你在arcade.draw_text前面加个print语句看看,是不是一直输出

https://www.soinside.com/question/gnHajyM7bBhMQMMVpFvhx8