Search code examples
pythonmemorypanda3d

panda3d running out of memory


While following this tutorial on how to use panda3d with python and code a simple 3d arcade flight game, I got an error when running the code from Issue 5 loading some 2d GUI Images. The error report in the console said:

Out of memory allocating 4016 bytes

Process finished with exit code 134

After quite a bit of googling, I still cannot tell why this happens. The GUI elements are just a few kilobytes, and the way larger files are loaded without any problems.

I am using panda3d v1.9 with python 2.7 on lubuntu (4gb RAM installed).

Any help is greatly appeciated.

The complete sourcecode with images can be found here


Solution

  • It does run for me, albeit extremely slowly. Poking around a bit, it seems your world.bam file takes a very long time to load because it has a lot of vertices (in the millions, it seems) and thousands of separate meshes, and is therefore structured rather inefficiently.

    Even a very crude preprocessing of the .bam file to reduce the draw call count (by loading it, calling flattenStrong(), and then writing it out again) causes the load and render time to decrease dramatically. However, even then, it is still problematic, because the program is now testing for collisions against every individual triangle each frame.

    In a flight simulator game like this, it is more typical to use a terrain engine and/or a shader to dynamically alter the terrain topology based on a height map. This also allows you to test against the heightmap image to check if the plane is flying below the ground, which is far more efficient than doing an intersection check with the individual triangles.