I generated a p3d from my small game with packp3d (after solving the missing packp3d.p3d in 1.7.0). When starting the generated p3d with Panda a console window appears with:
Then nothing happens, the download image appears (after it downloaded everything) and the p3dpythonw.exe generates massive CPU load. I let the program run for 20 Minutes and nothing happened.
The p3d can be downloaded from here. The last lines in p3dcore.log are:
Try running the p3d file from the command line, with the command “panda3d -f myfile.p3d”. This will (a) show you the Python log output, which may give you a clue where it’s getting hung up, and (b) the -f parameter works around a minor bug in the 1.7.0 release of panda3d.exe.
I just tried that command on Windows XP with Panda 1.7.0 and Ubuntu 10.04 with the latest version from the build bot. In both cases, there are no messages in the console window, nothing happens and both processes generate loads of CPU load
Edit: With a generated standalone executable happens the same
OK, I’m guessing your Python code is not importing DirectStart, or otherwise not doing anything interesting at startup.
What is the Python code in your main.py?
I just installed panda3d and panda3d-runtime from the Ubuntu PPA. My main class is:
# some more code...
I imported DirectStart now, which gives me at least a gray window. Do I have to derive from DirectStart to make p3d-files work?
No, sorry, I’ve misled you.
The bottom line is, your program should run if you execute “python -c ‘import main’”. If it doesn’t, then it won’t run when you pack it into a p3d file either.
In your case, you have two choices: either import DirectStart, or derive from ShowBase and then remember to create an instance of your class in main.py. You should only have exactly one instance of ShowBase, never two; and importing DirectStart will create an instance of ShowBase, so you shouldn’t both import DirectStart and also derive from ShowBase in the same program.
Since you are deriving from ShowBase, it means you shouldn’t import DirectStart, but it does mean you need to have this line in your main.py:
game = Game()
I did not know that with ShowBase and DirectStart. I will remove that DirectStart-import (it works right now).
I found the problem: In my code I have
if __name__ == "__main__":
# run game....
so I can easily import that code into other modules.
In the P3D-environment is name set to “main” and then my check does not work anymore.
Thanks for your help!!
Yes, that seems to be a common mistake. People assume that importing main.py in the p3d file is the same as running it on the command line, which would set the name to “main” instead of “main”.
We’ve talked about making this change in practice, to make it more consistent with people’s expectations. If we did so, then it would be correct to check for name == “main”. The only problem with this is, it’s still not the same as running it on the command line; in particular, there’s an issue with the GIL and threads that behaves differently from a command-line file and from an explicitly-imported file. But for most naive uses, it will be the same.
Maybe you should add a note to the packp3d manual then