2

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

xXliolauXx
  • 1,273
  • 1
  • 11
  • 25
  • Are you sure you have enough RAM? Can you track the RAM utilisation while running your script? – CoMartel Oct 07 '15 at 15:17
  • @HarryPotfleur I know that every other program works without any issues, even Starcraft running over Wine. Since I'm a pretty bad Linux-Newb, I have no experience with RAM tracking under linux. From what I read it doesn't seem to be quite as easy as under windows. – xXliolauXx Oct 07 '15 at 15:31
  • On ubuntu you can have the equivalent of windows task manager by calling `top` or `htop` in a terminal. `htop` is a little more graphic and easy to read, but you need to install it : `sudo apt-get install htop`. This should be a good starting point. Running starcraft doesn't mean much, as you can kill a 32Gb RAM with the "right" database loading. – CoMartel Oct 09 '15 at 07:48
  • @HarryPotfleur from what I see in htop I am nowhere close to the memory I still have available... it says something like 1.2gb of 2.7gb allocated with the program running. Also what surprised me is that when i disabled one of the game sounds to save some memory it all worked fine. Is there some sort of max memory for panda 1.9? – xXliolauXx Oct 09 '15 at 09:19
  • I don't think panda have a limited memory. If the issue is not with your RAM, I don't know where it come from. You should try posting your issue as a comment of the tutorial, see if anyone got the same problem – CoMartel Oct 09 '15 at 11:36

1 Answers1

2

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.

rdb
  • 1,488
  • 1
  • 14
  • 24
  • Thanks for that very nice answer. Could you also explain how to implement such a dynamic terrain generation? – xXliolauXx Oct 10 '15 at 15:57
  • GeoMipTerrain is a class for purely CPU-based terrain, which is documented in the Panda3D manual. Nowadays, depending on your desired target hardware, it may be an option to write a GLSL tessellation shader instead. A middle ground is to use a pre- tessellated quad and move the vertices to match the terrain heightmap using a vertex shader. – rdb Oct 10 '15 at 17:20