0

So I was working on a larger project and testing on a Mac when I noticed some weird behavior. I'm using Python 3.9.1 and macOS 11.0.1 – the bug doesn't occur on Windows 7, and I haven't tested other versions of macOS or Windows.

I'm using Tkinter for an initial setup window and then switching to Pygame, and in between, I do some cleanup of all the Tkinter variables – theoretically they don't matter, since I'm not using Tkinter for anything after that. Once the Pygame window opens, everything is fine, but if I click on another window to defocus Pygame, and then focus on the Pygame window again, it crashes with the following output:

pygame 2.0.0 (SDL 2.0.12, python 3.9.1)
Hello from the pygame community. https://www.pygame.org/contribute.html
called Tcl_FindHashEntry on deleted table
zsh: abort      python3 test.py

The minimum to consistently replicate this issue is

import pygame
import tkinter as tk
from time import sleep

root = tk.Tk()

try:
    root.mainloop()
except tk.TclError:
    pass

del root

pygame.init()
screen = pygame.display.set_mode((100, 100))

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            print('User quit.')
            exit()
    pygame.display.flip()
    sleep(0.025)

If I remove the del root then it doesn't crash, so it's not actually a big issue for my project – I don't need to remove the reference to root. But is there a better solution that can prevent the problem and still allow me to clean up the Tkinter references once I'm done with it?

Rabbid76
  • 177,135
  • 25
  • 101
  • 146
  • I should add: if anyone has a more specific idea as to what the actual issue is, I may file a bug report. My first instinct is it's a problem either with Python's Tcl backend or garbage collection with Tcl objects, but the fact that it happens only by interacting with the Pygame window is confusing. – helpmeplease Dec 28 '20 at 06:34
  • What does `root.eval("info patchlevel")` report? – Donal Fellows Dec 28 '20 at 14:15
  • It reports 8.6.8 – helpmeplease Dec 28 '20 at 20:58

0 Answers0