Error on closing application window

Hello

I am very new to Panda and I ran into an issue during the tutorial :

When I close the application with the top right button (on Windows) it crashes without a lot of informations about the reason :

Stack trace:
 >  File "C:\Users\Lilyel\Documents\MiscProjects\Panda3DGettingStarted\Panda3DGettingStarted.py", line 12, in <module>
 >    app.run()
Loaded '__main__'

Here’s the code that I run :

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)

app = MyApp()
app.run()

I have the same issue with the asteroids sample.

I also ran the setup.py to create an executable, when I close the window the processus is still running in the task manager.

I run the script with Visual Studio 16.1.5 and Python 3.7.3 (64-bit)
Here’s the list of the python packages that I have installed :

Package           Version
----------------- -------
astroid           2.2.5
colorama          0.4.1
isort             4.3.21
lazy-object-proxy 1.4.1
mccabe            0.6.1
panda3d           1.10.3
pip               19.1.1
pylint            2.3.1
setuptools        41.0.1
six               1.12.0
typed-ast         1.4.0
wrapt             1.11.2

When I use the terminal instead of Visual Studio, closing the application make the terminal freeze.

I know it is not much informations but, hopefully, somebody will have some ideas on how to resolve this (or get more informations).

Thanks for your help.

First off, assuming your using 1.10.x, make sure you’re using 1.10.3 since there have been quite a few bug fixes in each bug fix release.

Could you please post all of the terminal output and any error messages from Windows (e.g., error dialogs)?

Yes I am using 1.10.3.

Here’s the terminal output :

Known pipe types:
  wglGraphicsPipe
(all display modules loaded.) 

When I close the application started with the terminal, there is no additional messages and I can’t do anything with the terminal except closing it.

With the executable generated by the setup.py, the window closes but the process is still here in the background processes.

With Visual Studio I get this error message :

The details message (get when I clicked on “Copy Details” from the screen above) :

 Message=
  Source=C:\Users\Lilyel\Documents\MiscProjects\Panda3DGettingStarted\Panda3DGettingStarted.py
  StackTrace:
  File "C:\Users\Lilyel\Documents\MiscProjects\Panda3DGettingStarted\Panda3DGettingStarted.py", line 12, in <module>
    app.run()

I found a lead !

I tested the same code (from the tutorial) on a different computer with Windows 10 version 1803 and it worked perfectly then I updated Windows 10 to 1903 and it started to have this issue.

Prompted by that discovery, I ran a quick search, and may have found the source of the problem.

In short, it appears that there was a change in that version of Windows 10 that caused it to open the Microsoft Store when “python” or “python3” was run. The intention seems to have been to help new users to install Python under Windows 10.

Full article:
https://devblogs.microsoft.com/python/python-in-the-windows-10-may-2019-update/

Based on a comment-reply in that article, it looks like editing your PATH variable may help.

If not, the thread in which I encountered that article also includes another potential fix–but it is one that has some risks, I think. In case you want it, here is the thread:

Thank you for the links.

I tried these :

  • Disable aliases for Python in the applications settings (it removes the two commands added with the 1903 that open the store when typing the python command in the WindowsApps folder)

  • Use the Python installation from the Windows Store

  • Put the Python variable at the top of the list, above the ones for the WindowsApps

  • Remove from the PATH the variables to the WindowsApps folder

None of these solutions seem to solve the problem.

When I run where python it returns only one result :

C:\Users\Lilyel>where python
C:\Users\Lilyel\AppData\Local\Programs\Python\Python37\python.exe 

So I guess there is no conflict with the commands from the 1903 update.

What happens if you run Python from the command-line? Do you get a working interpreter?

And if so, what happens if you run your program from the command-line (i.e. as “python <your_Python_file>.py”)? Do you get any more output?

Yes, when I run Python from the command-line I get the interpreter :

C:\Users\Lilyel>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 2+2
4
>>>  

When I run my script from the command-line I get :

C:\Users\Lilyel\Documents\MiscProjects\Panda3DGettingStarted>python Panda3DGettingStarted.py
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)

Then if I close the application window, nothing else is printed and I can’t do anything in the terminal (type something, ctrl-C).

Very odd.

In that case, I don’t know, I’m afraid. Sorry! :/

Hmm… Presuming that no-one else has any suggestions, perhaps it might be worth experimenting a bit, trying the following:

  • Write a short non-Panda Python program, and run that from the terminal; see whether it crashes on exit.
    • If it doesn’t crash, and if feasible, write a short non-Panda GUI program, and run it from terminal as above.
  • If feasible, find another non-Panda Python program–preferably one that opens a window, and run that from the terminal; see whether that closes on exit.

These tests might indicate whether the problem lies in Panda, or elsewhere.

This script (TestSimple.py) :

print( 'Simple Python Program' )

Gives :

C:\Users\Lilyel\Documents\MiscProjects\TestsPython>python TestSimple.py
Simple Python Program

C:\Users\Lilyel\Documents\MiscProjects\TestsPython>

There are no error or crash and I can still use the terminal.

With this script (TkinterSimple.py) :

import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.width = 500
        self.height = 500

root = tk.Tk()
app = Application(master=root)
app.mainloop()

It opens a simple window and when I close it, there are no error or crash and I can still use the terminal :

C:\Users\Lilyel\Documents\MiscProjects\TestsPython>python TkinterSimple.py

C:\Users\Lilyel\Documents\MiscProjects\TestsPython>

And finally, with this one (TkinterComplex.py) :

import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red",
                              command=self.master.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        print("hi there, everyone!")

root = tk.Tk()
app = Application(master=root)
app.mainloop()

It opens a window with a button that prints a message and a button that closes the window. When I quit the application (using the in-app quit button or the window close button) there are still no crash or error :

C:\Users\Lilyel\Documents\MiscProjects\TestsPython>python TkinterComplex.py
hi there, everyone!

C:\Users\Lilyel\Documents\MiscProjects\TestsPython>

And I can continue to use the terminal.

Interesting. So it does look like the problem may lie with Panda3D–or specifically between Panda3D and Windows 10 with that update, perhaps.

I don’t know the source of the problem myself, I’m afraid. :/ So, for now at least I bow out, and leave it to others who might have have a better idea of what might be awry!

I think we should be the same problem, I have not solved it yet.