out of memory when downloading objects

Started by arianaa30, July 15, 2012, 10:54:31 AM

Previous topic - Next topic

arianaa30

Hi,
In my demo, I've got almost 20 objects and corresponding textures. Everything at this moment works, but when I just change one of these objects to be downloaded from somewhere, I get out of memory error. Is there any tips for that?
(Finally I have to download all of these 20 objects, similar to waterput)

Here after getting the .md2 file, I add it to the world.

waterput = Loader.loadMD2(stream("waterput.md2"),1f);
tm.addTexture("waterput", new Texture(res.openRawResource(R.raw.waterputtex)));
waterput.setTexture("waterput");
waterput.clearAnimation();
waterput.translate(170, -35, -130);
world.addObject(waterput);
waterput.strip();


This is the method which gets a name, receives the object from a URL and returns it.

BufferedInputStream stream(String name) throws IOException{
//TODO
String objURL = "http://www.xxx.edu/xxx/"+name;
URLConnection conn = new URL(objURL).openConnection();
conn.connect();
BufferedInputStream bis = new BufferedInputStream(conn
.getInputStream());
Loader.clearCache();

return bis;
}

btw, I do not need all the keyframes in the .md2 files, so I call clearAnimation() to remove them.

EgonOlsen

Have you tried not to use a BufferedInputStream but the InputStream from the connection instead? The loader actually does it's own buffering, so this shouldn't be needed and will consume additional memory (not sure if this is a problem though).

arianaa30

I corrected it; It should have some effects, however I still get the error. Maybe that is because of this specific object.
I thing I want to know is that does it make much difference in terms of memory for object reading if we are getting them from the raw resources (using openRawResource) or we get them using network connection? Since you know, we do not actually download the object to store it somewhere; but we just get the inputStream.

EgonOlsen

For the loader, this makes no difference. If there is a difference, it comes from the network stuff and is outside of the scope of jPCT-AE. To fight memory usage, please have a look at this too: http://www.jpct.net/wiki/index.php/Reducing_memory_usage

arianaa30

#4
Egon, a strange problem:
I found out when I want to load Serialized Objects from the web, the demo hangs/crashes!! for other file types (.obj, .md2, .3ds) everything works. Is there anything happening here which I'm not aware of?
(btw, it is in a second thread.)


grass = Loader.loadSerializedObject(stream("sergrass.ser"));
tm.addTexture("grass", new Texture(stream("grasstex.jpg")));
grass.setTexture("grass");
grass.translate(-85, -17, -70);
grass.rotateZ((float) Math.PI);
grass.setTransparency(10);
world.addObject(grass);
grass.strip();

EgonOlsen

You are not supposed to fiddle around with the World in another one than the rendering thread. So you can load your model in that thread, but you may not add it there. Because if that interferes with the rendering, you'll get random results from display errors to exceptions.

arianaa30

Yes, got it. However I fixed it by moving the .ser object downloading files to the main thread. I was wondering why everything works, except for the loadSerializedObject responsible for loading .ser files!!!!

EgonOlsen

The loader shouldn't cause the problem but the addObject()-call from outside the rendering thread. Anyway, if it's solved now...

arianaa30

#8
Yeah; Thanks a lot  :)
Btw, so we should put all the downloading stuffs in the 2nd thread, and just put the addObject to the main thread. The threads are concurrently being executed; so when reaching the addObject, how should it find out if that specific object was already downloaded in the 2nd thread, so to add it now?!  :o

EgonOlsen

Just set some flag once the loading thread is done and evaluate that flag in the other thread.