Pygame分段错误:分类和递归问题?

时间:2017-03-06 23:16:28

标签: python recursion menu pygame

处理此项目:https://github.com/Roland00111/Trumpocalypse/tree/Recursion/Trumpoclypse%20UI。该程序以python Trumpocalypse.py开始。

错误是:

Fatal Python error: (pygame parachute) Segmentation Fault
Aborted (core dumped)

在另一台机器上有一个关于最大递归深度的输出。有几个地方可能会发生递归。

在名为Menu的类中调用事件循环时有一个pygame。只要按下回车键,while事件循环就会停止。然后调用一个新的Menu类。然后这个新的Menu类启动一个新的while事件循环。 Menu类是主Menu类的所有子类。

由于每个新的Menu类都在上一个菜单中启动,因此可能会发生递归。

例如Menu:OpeningMenu()运行第一个while事件循环。 然后,如果选择了第一个菜单:CreateCharacter()运行一个新的while事件循环。 然后,如果选择了第二个项目菜单:CreateCharacterAutomatic()运行一个新的while事件循环。 然后,如果选择了第一个菜单:StoryScreen()运行一个新的while事件循环。 现在选择第一个项目大约60次。这在Menu:StoryScreen()和Menu:DayScreen()的新实例之间交替。在大约第60次之后,将发生段错误。

有趣的是,在Menu:DayScreen()代码之前的任何地方迭代时,似乎不会发生段错误。所以从Menu:OpeningMenu()到Menu:HighScores()并再次无休止地返回不会导致段错误。然而,这里有趣的是:当进入Menu的第一个实例时:DayScreen()它会立即发生段错误。也就是说,在第一次打开Menu:DayScreen()并且确实发生了段错误时,已经设置了需要60个东西的计数器。

运行previous_menu.__del__()似乎无法解决问题。虽然这确实退出了上一个菜单,但在Menu:DayScreen()期间仍然存在分段错误。

更新

现在看:

RuntimeError: maximum recursion depth exceeded while getting the str of an object

这是在为每个继承类菜单实现两个调用之后:

Menu.__init__(self)
previous_menu.__del__()

其中previous_menu是启动当前实例的最后一个Menu实例。这是Pygame的一个问题,还是代码在Python中调用类的问题?

重现错误:选择"开始",选择"自动",选择"开始冒险",选择"开始日" ,选择"次日"。现在继续做"开始日"和#34;第二天"约120次(每次60次)。大约在这个时候,递归错误将会触发。

以下是完整输出:

Traceback (most recent call last):
  File "Trumpocalypse.py", line 826, in <module>
    GameState()
  File "Trumpocalypse.py", line 495, in __init__
    self.current_screen = OpeningMenu() # Start the events while loop.
  File "Trumpocalypse.py", line 789, in __init__
    self.keypressFunction()
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 766, in __init__
    self.keypressFunction()
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 638, in __init__
    self.keypressFunction(Text,32)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__
    self.keypressFunction(text,32,20,300) #Looks the same as highscore
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 745, in __init__
    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 725, in __init__

...

    self.keypressFunction(text,32,60,250) # Pass text (text,font size,top allignment,height of box)
  File "Trumpocalypse.py", line 275, in keypressFunction
    self.keypressArray[chosen_position](self)
  File "Trumpocalypse.py", line 689, in __init__
    Menu.__init__(self)
RuntimeError: maximum recursion depth exceeded while calling a Python object
__del__ <__main__.DayScreen instance at 0x7f7bee5eddd0>
__del__ <__main__.StoryScreen instance at 0x7f7bee5edcb0>
__del__ <__main__.DayScreen instance at 0x7f7bee5edb00>
__del__ <__main__.StoryScreen instance at 0x7f7bee5ed9e0>
__del__ <__main__.DayScreen instance at 0x7f7bee5ed830>
__del__ <__main__.StoryScreen instance at 0x7f7bee5ed710>
__del__ <__main__.DayScreen instance at 0x7f7bee5ed560>
__del__ <__main__.StoryScreen instance at 0x7f7bee5ed440>
__del__ <__main__.DayScreen instance at 0x7f7bee5ed290>
__del__ <__main__.StoryScreen instance at 0x7f7bee5ed170>
__del__ <__main__.DayScreen instance at 0x7f7bee5e7f80>
__del__ <__main__.StoryScreen instance at 0x7f7bee5e7e60>
__del__ <__main__.DayScreen instance at 0x7f7bee5e7cb0>
__del__ <__main__.StoryScreen instance at 0x7f7bee5e7b90>
__del__ <__main__.DayScreen instance at 0x7f7bee5e79e0>
__del__ <__main__.StoryScreen instance at 0x7f7bee5e78c0>
__del__ <__main__.DayScreen instance at 0x7f7bee5e7710>
__del__ <__main__.StoryScreen instance at 0x7f7bee5e75f0>
__del__ <__main__.DayScreen instance at 0x7f7bee5e7440>
__del__ <__main__.StoryScreen instance at 0x7f7bee5e7320>
__del__ <__main__.DayScreen instance at 0x7f7bee5e7170>
__del__ <__main__.StoryScreen instance at 0x7f7bee5e7050>
__del__ <__main__.DayScreen instance at 0x7f7bee5e1e60>
__del__ <__main__.StoryScreen instance at 0x7f7bee5e1d40>
__del__ <__main__.DayScreen instance at 0x7f7bee5e1b90>
__del__ <__main__.StoryScreen instance at 0x7f7bee5e1a70>
__del__ <__main__.DayScreen instance at 0x7f7bee5e18c0>
__del__ <__main__.StoryScreen instance at 0x7f7bee5e17a0>

__del__ <__main__.DayScreen instance at 0x7f7bee5e15f0>
__del__ <__main__.StoryScreen instance at 0x7f7bee5e14d0>
__del__ <__main__.DayScreen instance at 0x7f7bee5e1320>
__del__ <__main__.StoryScreen instance at 0x7f7bee5e1200>
__del__ <__main__.DayScreen instance at 0x7f7bee5e1050>
__del__ <__main__.StoryScreen instance at 0x7f7bee659ef0>
__del__ <__main__.DayScreen instance at 0x7f7bee659d40>
__del__ <__main__.StoryScreen instance at 0x7f7bee659c20>
__del__ <__main__.DayScreen instance at 0x7f7bee659a70>
__del__ <__main__.StoryScreen instance at 0x7f7bee659950>
__del__ <__main__.DayScreen instance at 0x7f7bee6597a0>
__del__ <__main__.StoryScreen instance at 0x7f7bee659680>
__del__ <__main__.DayScreen instance at 0x7f7bee6594d0>

...

__del__ <__main__.StoryScreen instance at 0x7f7bee92bd40>
__del__ <__main__.DayScreen instance at 0x7f7bef066710>
__del__ <__main__.StoryScreen instance at 0x7f7bef08e6c8>
__del__ <__main__.CreateCharacterAutomatic instance at 0x7f7bee92b638>
__del__ <__main__.CreateCharacter instance at 0x7f7bee92b9e0>
__del__ <__main__.OpeningMenu instance at 0x7f7bee6b3b48>

解决方案

该类正在调用另一个类并因此递归。 (将父实例传递给子节点,以便子节点指示父节点自己结束,或者无法正常工作或未正确实现。)例如:

class Menu1():
    def __init__(self):
        Menu2(self)
class Menu2():
    def __init__(self, previous):
        previous.__del__() # Not working.

现在的解决方案是让父类指导要调用的类。例如:

class Menu1():
    def __init__(self):
        pass
class Menu2():
    def __init__(self):
        pass
a=Menu1()
a=Menu2()

这有效并且不会遇到递归问题。

1 个答案:

答案 0 :(得分:2)

您必须重新考虑您的菜单系统。 keypressFunction子类的__init__Menu方法会导致递归。

在Menu子类的每个__init__方法中,您调用self.keypressFunction,然后实例化第275行self.keypressArray[chosen_position](self)中的下一个Menu子类,该self.keypressFunction在其__init__中调用ItemTouchHelper再次等等,直到Python和Pygame崩溃,因为超过了1000次递归的递归限制。

以下是iminurnamez的simple finite state machine的一个很好的例子,您可以使用它来实现场景和菜单。