We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Applet: java.lang.OutOfMemoryError
Page Index Toggle Pages: 1
Applet: java.lang.OutOfMemoryError (Read 712 times)
Applet: java.lang.OutOfMemoryError
Jan 14th, 2006, 5:47am
 
I've made an applet of a sphere with a texture map of the earth:
http://www.backspaces.net/files/play/

It has the ability to load images of the earth of three sizes: 2048, 4096, 8192 horizontally, .. half that vertically.  The smallest is the default.

Whenever I try to load one of the larger images in the applet, by using the 2 or 3 keyboard key, I eventually get a java out of memory error.  When running in the Processing desktop environment, I don't get these, although I follow the hint in the FAQ for expanding my memory: Xms128m -Xmx1024m.

Is there a way to get my applet to be initialized with more memory?  Or some way to conserve memory within Processing so that the memory limit is not reached?

Owen
Re: Applet: java.lang.OutOfMemoryError
Reply #1 - Jan 14th, 2006, 6:44pm
 
In general Java is designed to avoid massive amounts of memory being allocated at one time, while you might want to do this, in general you can optimize your code considerably if you take certain factors into account.

For starters you should break the earth images into smaller pieces, and load them individually as needed.  After all, you can never see more than half of the map at any one time.  Then you can be even more clever if you calculate what the actual resolution of the polygons is, then load the appropriate low/med/high resolution based on what they can actually see.  That is, if you're zoomed out to see the entire globe on the applet you have now, you'll never see more than the 2048 detail (assuming 1024 is displayed at a time, and the applet is less than 1024 pixels wide).  If you zoom in, you're only seeing part of the globe, so you should only load the texture pieces that are visible.

A good example of this in action would be Google Earth.  If it actually loaded the entire globe at one time, your computer would hang.  While eventually computers will be able to handle it, the optimizations above offer zero loss of quality (it may actually increase quality because you will be mimicking a mip-map technique) while increasing speed and saving resources for doing other things.

On a side note, abug: Whenever I hit a key on the applet, the globe repositions temporarily before restoring.
Page Index Toggle Pages: 1