simon-heinen / droidar

DroidAR Mobile Locationbased Augmented Reality Framework for Android
GNU General Public License v3.0
225 stars 275 forks source link

OutOfMemoryException #28

Open spiritinlife opened 10 years ago

spiritinlife commented 10 years ago

I am playing around with your awesome lib and i came across this error. OutOfMemory Exception ( I will try to add some logs ) What i am doing is that i get 5 icons from the camera folder and i pass them from the MainActivity to the Setup class as bitmaps. After that i use this code to create MeshComponents MeshComponent imageMesh = GLFactory.getInstance().newTexturedSquare( "icon" + scounter, bitmap);

I get this error when trying to load the second image. I have overcame this error by commenting out that line texture = TextureManager.getInstance().resizeBitmapIfNecessary(texture); which is at gl.textures.textureShape. textureShape constructor. It seems to me that it always tries to recreate the bitmap resulting in OutOfMemory error.

simon-heinen commented 10 years ago

Hm normally the resizeBitmapIfNecessary is needed if the textures do not have a size with power of two so e.g. 256x128, so just leaving this method call away might cause crashes on some devices which can only handle such textures (actually I thought all devices can only handle such textures). Maybe you try to call a manual garbage collect after you loaded each image instead? but normally loading 5 images should not be a problem at all, only if you have very big images

spiritinlife commented 10 years ago

-Maybe you try to call a manual garbage collect after you loaded each image instead? --When i decode my images Path to a Bitmap i use the BitmapMarker Options to tell the GC that i you want more memory, the bitmap can be released.I did that because my activity would crach with OutOfMemoryException before even getting to the setup class.The mighty nexus 4 :) could not handle loading into memory 3-4 images.So that GC may be the problem.

-but normally loading 5 images should not be a problem at all, only if you have very big image. --Do you think i can push that limit somehow ?

simon-heinen commented 10 years ago

wath resolution are these images? did you enable the large heap flag in your android manifest? that could help.

spiritinlife commented 10 years ago

It seems like this large heap flag helped a lot thx. I don't have much time these days to test it further.I will come back with more details when i have time. Thank you for your helpful responses.

simon-heinen commented 10 years ago

That this flag helped also indicates that you are using to big images ;-) did you check the resolution? I wouldn't use something bigger than 1200x1200 , in the ar world they will not be smaller just because you reduce the resolution Am 05.06.2014 23:06 schrieb "George Chailazopoulos" < notifications@github.com>:

It seems like this large heap flag helped a lot thx. I don't have much time these days to test it further.I will come back with more details when i have time. Thank you for your helpful responses.

— Reply to this email directly or view it on GitHub https://github.com/bitstars/droidar/issues/28#issuecomment-45274915.

spiritinlife commented 10 years ago

Well the images come from the camera folder ,so the purpose of the app is to handle all images that have been taken using the phones camera. So my guess is that the resolution of the image will be changing from device to device and it will be dependent to the camera(but i am no expert :) ) .Anyway i will check in what resolution*how many images i get this error with nexus 4 and i will come back again.