glob3mobile / g3m

The multiplatform advanced visualization framework
http://www.glob3mobile.com/
Other
116 stars 56 forks source link

out of memory error on android #12

Closed akosmaroy closed 10 years ago

akosmaroy commented 10 years ago

Hi,

I'm experimenting with a simple code sample with g3m on Android, and I consintently get an out of memory exception. my code is a very simple activity:

public class MainActivity extends Activity {

    private G3MWidget_Android g3mWidget;
    private FlyTo flyTo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Sector demSector = new Sector(Geodetic2D.fromDegrees(45.9, 7.6),
                                      Geodetic2D.fromDegrees(47.5, 9));

        final ElevationDataProvider dem = new SingleBillElevationDataProvider(
                new URL("file:///elev.bil", false), demSector,
                   new Vector2I(576, 504), 0);

        final G3MBuilder_Android builder = new G3MBuilder_Android(this);
        builder.getPlanetRendererBuilder().setElevationDataProvider(dem);
        g3mWidget = builder.createWidget();

        G3MWidget g3mw = g3mWidget.getG3MWidget(); 

        g3mw.setCameraPosition(Geodetic3D.fromDegrees(46.1389694, 8.7644777, 851.89));
        g3mw.setCameraHeading(Angle.fromDegrees(81.9));
        g3mw.setCameraPitch(Angle.fromDegrees(90.74));

            final LinearLayout layout = (LinearLayout) findViewById(R.id.glob3);
        layout.addView(g3mWidget);
    }
}

where elev.bil is a file I got by the following URL:

http://data.worldwind.arc.nasa.gov/elev?REQUEST=GetMap&SERVICE=WMS&VERSION=1.3.0&LAYERS=srtm30&STYLES=&FORMAT=image/bil&CRS=EPSG:4326&BBOX=45.9,7.6,47.5,9&WIDTH=576&HEIGHT=504

and after a short while, the exception I get is always the same:

12-10 14:10:45.133: W/dalvikvm(1576): threadid=14: thread exiting with uncaught exception (group=0x409c01f8)
12-10 14:10:45.133: E/AndroidRuntime(1576): FATAL EXCEPTION: Downloader_WorkerThread #2
12-10 14:10:45.133: E/AndroidRuntime(1576): java.lang.OutOfMemoryError
12-10 14:10:45.133: E/AndroidRuntime(1576):     at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
12-10 14:10:45.133: E/AndroidRuntime(1576):     at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:424)
12-10 14:10:45.133: E/AndroidRuntime(1576):     at org.glob3.mobile.specific.Downloader_Android_Handler.decodeImage(Downloader_Android_Handler.java:233)
12-10 14:10:45.133: E/AndroidRuntime(1576):     at org.glob3.mobile.specific.Downloader_Android_Handler.runWithDownloader(Downloader_Android_Handler.java:225)
12-10 14:10:45.133: E/AndroidRuntime(1576):     at org.glob3.mobile.specific.Downloader_Android_WorkerThread.run(Downloader_Android_WorkerThread.java:59)
12-10 14:10:46.384: I/dalvikvm-heap(1576): Clamp target GC heap from 64.543MB to 64.000MB
12-10 14:10:46.394: I/dalvikvm-heap(1576): Forcing collection of SoftReferences for 262160-byte allocation
12-10 14:10:46.524: I/dalvikvm-heap(1576): Clamp target GC heap from 64.541MB to 64.000MB
12-10 14:10:46.524: E/dalvikvm-heap(1576): Out of memory on a 262160-byte allocation.
akosmaroy commented 10 years ago

if I use a WMSBillElevationDataProvider instead, like this:

        ElevationDataProvider dem = new WMSBillElevationDataProvider(
                new URL("http://data.worldwind.arc.nasa.gov/elev"), "srtm30",
                demSector, 0);

I still get an out of memory error, although the stack trace is different:

12-10 14:16:46.473: W/dalvikvm(1637): threadid=11: thread exiting with uncaught exception (group=0x409c01f8)
12-10 14:16:46.473: E/AndroidRuntime(1637): FATAL EXCEPTION: GLThread 129
12-10 14:16:46.473: E/AndroidRuntime(1637): java.lang.OutOfMemoryError
12-10 14:16:46.473: E/AndroidRuntime(1637):     at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
12-10 14:16:46.473: E/AndroidRuntime(1637):     at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:424)
12-10 14:16:46.473: E/AndroidRuntime(1637):     at org.glob3.mobile.specific.SQLiteStorage_Android.readImage(SQLiteStorage_Android.java:255)
12-10 14:16:46.473: E/AndroidRuntime(1637):     at org.glob3.mobile.generated.CachedDownloader.getCachedImageResult(CachedDownloader.java:48)
12-10 14:16:46.473: E/AndroidRuntime(1637):     at org.glob3.mobile.generated.CachedDownloader.requestImage(CachedDownloader.java:135)
12-10 14:16:46.473: E/AndroidRuntime(1637):     at org.glob3.mobile.generated.TileTextureBuilder.start(TileTextureBuilder.java:151)
12-10 14:16:46.473: E/AndroidRuntime(1637):     at org.glob3.mobile.generated.TileTextureBuilderStartTask.execute(TileTextureBuilderStartTask.java:20)
12-10 14:16:46.473: E/AndroidRuntime(1637):     at org.glob3.mobile.generated.FrameTasksExecutor.doPreRenderCycle(FrameTasksExecutor.java:103)
12-10 14:16:46.473: E/AndroidRuntime(1637):     at org.glob3.mobile.generated.G3MWidget.render(G3MWidget.java:190)
12-10 14:16:46.473: E/AndroidRuntime(1637):     at org.glob3.mobile.specific.ES2Renderer.onDrawFrame(ES2Renderer.java:64)
12-10 14:16:46.473: E/AndroidRuntime(1637):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
12-10 14:16:46.473: E/AndroidRuntime(1637):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
12-10 14:16:47.144: I/dalvikvm-heap(1637): Clamp target GC heap from 64.009MB to 64.000MB
12-10 14:16:47.144: I/dalvikvm-heap(1637): Forcing collection of SoftReferences for 262160-byte allocation
12-10 14:16:47.403: I/dalvikvm-heap(1637): Clamp target GC heap from 64.008MB to 64.000MB
12-10 14:16:47.413: E/dalvikvm-heap(1637): Out of memory on a 262160-byte allocation.
mdelacalle commented 10 years ago

For the correct working of G3M is needed to set on AndroidManifest.xml the property android:largeHeap=true in the Application tag. http://developer.android.com/guide/topics/manifest/application-element.html

Anyway, with this property set true, this problem could be happen if you are loading a very large datasets, in that case you have to change the strategy loading the data (LoD, etc...) Surely your app is going to work correctly only setting this label.

Thanks.

akosmaroy commented 10 years ago

my main issue is that I don't seem to have control over this out of memory incident. even if I set largeHeap=true, and I don't have anything else in my app (no other objects present other than G3MWidget), and is a generally clean android (not much else running), I still get an out of memory issue.

it would be nice to be able to control this in a way, so that G3M doesn't load that many bitmaps, etc. so that it drives itself out of memory

akosmaroy commented 10 years ago

Diego, I double-checked, and actually I'm on the purgatory branch.

to reproduce the issue, you just simply need to create an Activity with my code above, and just run. wait a little bit, you see that g3m is downloading more and more tiles, and trying to display in more and more detail. and then it runs out of memory :(