2017-03-06 3 views
0

An diesem Projekt arbeiten: https://github.com/Roland00111/Trumpocalypse/tree/Recursion/Trumpoclypse%20UI. Das Programm wird mit python Trumpocalypse.py gestartet.Fehler in der Pygame-Segmentierung: Problem mit Klassierung und Rekursion?

Der Fehler ist:

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

auf einer anderen Maschine eine Ausgabe über max Rekursionstiefe besteht. Es gibt einige Orte, wo Rekursion auftreten könnte.

Es gibt ein Pygame während der Ereignisschleife, die in einer Klasse namens Menu aufgerufen wird. Jedes Mal, wenn die Eingabetaste gedrückt wird, stoppt die Ereignisschleife. Dann wird eine neue Menüklasse aufgerufen. Und dann startet diese neue Menü-Klasse eine neue While-Event-Schleife. Die Menü-Klassen sind alle Unterklassen einer Haupt-Menü-Klasse.

Da jede neue Menu-Klasse im vorherigen Menü initiiert wird, tritt dort möglicherweise eine Rekursion auf.

Zum Beispiel Menü: OpeningMenu() führt die erste while-Ereignisschleife aus. Dann, wenn das erste Element ausgewählt ist Menü: CreateCharacter() führt eine neue while-Ereignisschleife aus. Dann, wenn das zweite Element ausgewählt ist Menü: CreateCharacterAutomatic() führt eine neue While-Ereignisschleife aus. Dann, wenn das erste Element ausgewählt ist Menü: StoryScreen() führt eine neue While-Ereignisschleife aus. Und jetzt wählen Sie den ersten Artikel etwa 60 mal. Dies wechselt zwischen neuen Instanzen von Menu: StoryScreen() und Menu: DayScreen(). Nach ungefähr dem 60. Mal wird der Segfault auftreten.

Interessant ist, dass der Segfault nicht auftritt, wenn vor dem Menü: DayScreen() Code irgendwo vorgelesen wird. Wenn Sie also von Menu: OpeningMenu() zu Menu: HighScores() und wieder endlos zurückkehren, wird der Segfault nicht ausgelöst. Interessant ist hier jedoch Folgendes: Wenn Sie zur ersten Instanz von Menu: DayScreen() gehen, werden sofort die Standardwerte angezeigt. Das heißt, welcher Zähler, der 60 von etwas benötigt, ist bereits beim ersten Öffnen von Menu: DayScreen() gesetzt und der Segfault tritt tatsächlich auf.

Running previous_menu.__del__() scheint das Problem nicht zu lösen. Obwohl dies tatsächlich das vorherige Menü verlässt, gibt es immer noch einen Segmentierungsfehler, der während Menu: DayScreen() auftritt.

aktualisieren

Jetzt sehen:

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

Dies ist nach für jede Vererbungs Klasse Menü zwei Anrufe Umsetzung:

Menu.__init__(self) 
previous_menu.__del__() 

Wo previous_menu das letzte Menü-Instanz, die die gestartet vorliegende Instanz. Ist das ein Problem mit Pygame oder ein Problem mit dem Aufruf der Klassen in Python durch den Code?

Um den Fehler zu reproduzieren: Wählen Sie "Start", wählen Sie "Auto", wählen Sie "Beginnen Sie Ihr Abenteuer", wählen Sie "Start Day", wählen Sie "Next Day". Machen Sie nun "Start Day" und "Next Day" etwa 120 Mal (jeweils 60 Mal). Ungefähr zu diesem Zeitpunkt wird der Rekursionsfehler ausgelöst.Hier

ist die volle Leistung:

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> 

Lösung

Die Klasse eine andere Klasse rief und damit Rekursion. (Vorbei an der übergeordneten Instanz, um das Kind für das Kind die Eltern anzuweisen, sich am Ende wurde entweder nicht funktioniert oder nicht korrekt implementiert.) Zum Beispiel:

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

Die Lösung für jetzt ist eine Elternklasse direkt zu haben, die Klassen zum Anrufen. Zum Beispiel:

Dies funktioniert und tritt nicht in das Problem mit Rekursion.

Antwort

2

Sie müssen Ihr Menüsystem überdenken. Die keypressFunction und die __init__ Methoden der Menu Unterklassen verursachen die Rekursion.

In jeder __init__ Methode des Menü Subklassen rufen Sie self.keypressFunction, die dann die nächste Menüunterklasse in Zeile instanziiert 275 self.keypressArray[chosen_position](self) die self.keypressFunction in seinem __init__ wieder und so weiter, bis Python und Pygame Absturz ruft, weil die Rekursion Grenze von 1000 Rekursion ist übertroffen.

Hier ist ein schönes Beispiel für eine simple finite state machine von iminurnamez, die Sie verwenden können, um Szenen und Menüs zu implementieren.

+0

Okay. Interessant. – There

+0

Okay. Also ein paar Änderungen vorgenommen und es scheint für jetzt in Ordnung zu sein. – There

+1

Problem: Jede Klasse hat eine andere Klasse angerufen und somit nie wirklich beendet. Z.B. 'Menu1(). Some_function: Menu2()'. Lösung: Lassen Sie eine Elternklasse angeben, welche Klassen angerufen werden sollen. Z.B. 'a = Menu1()' dann 'a = Menu2()'. – There