Author Topic: App crashes when I add an array of more than 200 spheres to the world  (Read 742 times)

Offline CarlosMB89

  • byte
  • *
  • Posts: 15
    • View Profile
I'm creating an array of more than 200 spheres for adding them to the world, but when 200 spheres more or less are created the app crashes and this error appear ("OutOfMemory).

Do you know what is the reason?? Because it sounds strange a out of memory error for only 200 spheres.....

Thanks

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: App crashes when I add an array of more than 200 spheres to the world
« Reply #1 on: December 03, 2014, 08:35:00 pm »
Because it sounds strange a out of memory error for only 200 spheres.....
That's a bit like finding it strange that "he's dead even if i've shot him only 10 times"... ;) 200 spheres is quite a lot, not "only". Are these all visible in one frame? If not, then you might want to consider a more MVC like approach that assigns views (i.e. Object3D) to potential visible sphere beans.
Anyway, how much memory is available to the VM depends on the Android version and the vendor and it ranges from 16mb to 512mb (at least i haven't seen anything about that }or now). If your spheres are all more or less equals, don't do something like:

Code: [Select]
for (int i=0; i<200; i++) {
    spheres.add(Primitives.getSphere(10));
}

But rather work with a blueprint object to share data between objects like so:

Code: [Select]
Object3D bp=Primitives.getSphere(10);
for (int i=0; i<200; i++) {
    Object3D s=new Object3D(bp, true);
    s.shareCompiledData(bp);
    spheres.add(s);
}

Offline CarlosMB89

  • byte
  • *
  • Posts: 15
    • View Profile
Re: App crashes when I add an array of more than 200 spheres to the world
« Reply #2 on: December 03, 2014, 11:36:48 pm »
Oh it works thank you very much EgonOlsen ;) ;). But I have one question....my curiosity XD... if android devices have so little memory...how does they run some games as Asphalt 8 for example, they have lots of 3D objects I suppose.

Thanks in advance

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: App crashes when I add an array of more than 200 spheres to the world
« Reply #3 on: December 03, 2014, 11:53:05 pm »
They aren't using the Android SDK (i.e. Java), but the NDK (i.e. C++), which doesn't have this limitations. However, if you need more memory inside the VM, check out the "android:largeHeap" setting for your AndroidManifest.xml