www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Kaiidyn on February 24, 2011, 02:41:09 pm

Title: Out of memory
Post by: Kaiidyn on February 24, 2011, 02:41:09 pm
I'm starting to get really frustrated with this error...

Code: [Select]
Out of memory on a 3527724-byte allocation.
 FATAL EXCEPTION: GLThread 9
 java.lang.OutOfMemoryError
     at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:93)
     at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:218)
     at com.threed.jpct.ZipHelper.unzip(ZipHelper.java:30)
     at com.threed.jpct.GLRenderer.convertTexture(GLRenderer.java:766)
     at com.threed.jpct.GLRenderer.setTextures(GLRenderer.java:2151)
     at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2064)
     at com.threed.jpct.World.draw(World.java:1341)
     at com.threed.jpct.World.draw(World.java:1122)
     at gp.itsolutions.Render.onDrawFrame(Render.java:87)
     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)

I am rewriting and cleaning the code for what I have now in my mmo game (in a separate project)
and get this error when (I think) loading the terrain from zip file (as ZipHelper is mentioned in the error)
But the fact is, I did not change anything compared to my old code, except for the fact that I created a separate class for loading and disposing the terrain...

Terrain class:
Code: [Select]
public class Terrain {
private Object3D terrain = null;
private Texture terrainTexture = null;
private ZipInputStream zis = null;

public Terrain(World world){
try {

if(terrainTexture == null)
terrainTexture = new Texture(Gameplay.resources.openRawResource(R.raw.terraintexture));

if(!TextureManager.getInstance().containsTexture("terrainTexture"))
TextureManager.getInstance().addTexture("terrainTexture", terrainTexture);

if(zis == null){
zis = new ZipInputStream(Gameplay.resources.openRawResource(R.raw.terrain));
zis.getNextEntry();
}

if( (terrain == null) && (zis != null) ){

terrain = Loader.loadSerializedObject(zis);

terrain.setScale(20);
terrain.setTexture("terrainTexture");
//F.tileTexture(terrain, 25);
terrain.compile();
terrain.build();
world.addObject(terrain);

}

} catch (Exception e) {
e.printStackTrace();
}
}

public void dispose(){
if(terrainTexture != null){ terrainTexture = null; }
if(terrain != null){ terrain = null; }
if(zis != null){ try { zis.close(); } catch (IOException e) { } zis = null; }
}
}

I have tried several attempts to try and fix it, but I can't get the right one..
Figured a second pair of eyes might help..
Title: Re: Out of memory
Post by: EgonOlsen on February 24, 2011, 03:00:28 pm
It crashes while converting the texture (how large is it?) not while loading the zip. You can easily spot that in the stack trace.
I've a few hints, but i don't think that they'll cut it:

Title: Re: Out of memory
Post by: EgonOlsen on February 24, 2011, 03:02:31 pm
And another one:

Title: Re: Out of memory
Post by: Kaiidyn on February 24, 2011, 04:45:00 pm
The preWarm on the TextureManager fixed the first problem :)

Code: [Select]
public class Terrain {
private Object3D terrain = null;
private Texture terrainTexture = null;

public Terrain(World world){


if(terrainTexture == null){
terrainTexture = new Texture(Gameplay.resources.openRawResource(R.raw.terraintexture));
terrainTexture.enable4bpp(true);
}
if(!TextureManager.getInstance().containsTexture("terrainTexture"))
TextureManager.getInstance().addTexture("terrainTexture", terrainTexture);

TextureManager.getInstance().preWarm(Gameplay.render.frameBuffer);

ZipInputStream zis = new ZipInputStream(Gameplay.resources.openRawResource(R.raw.terrain));
try {
zis.getNextEntry();
} catch (IOException e) {
throw new RuntimeException(e);
}

if( (this.terrain == null) ){

this.terrain = Loader.loadSerializedObject(zis);
this.terrain.strip();
this.terrain.setScale(20);
this.terrain.setTexture("terrainTexture");
//F.tileTexture(terrain, 25);
this.terrain.forceGeometryIndices(true);
this.terrain.compile();
this.terrain.build();
world.addObject(this.terrain);

}else{
Log.e("Terrain already loaded..");
}

try {
zis.close();
zis = null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void dispose(){
if(terrainTexture != null){ terrainTexture = null; }
if(terrain != null){ terrain = null; }
}
}
Do I still need to call terrain.compile() after terrain.forceGeometryIndices(true) ? (or before?)
And is this the proper way to use enable4bpp, as I assume the texture is already being loaded when initializing the terrainTexture variable, the enable4bpp will need to convert it to 4bpp which in turn will consume more memory (or cpu)

When I call onStop and dispose everything (or nullify) and restart the game, it is giving another out of memory error
Code: [Select]
ERROR/dalvikvm-heap(4283): 288000-byte external allocation too large for this process.
 FATAL EXCEPTION: GLThread 10
 java.lang.OutOfMemoryError
     at org.apache.harmony.luni.platform.OSMemory.malloc(Native Method)
     at org.apache.harmony.luni.platform.PlatformAddressFactory.alloc(PlatformAddressFactory.java:150)
     at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:66)
     at java.nio.ReadWriteDirectByteBuffer.<init>(ReadWriteDirectByteBuffer.java:51)
     at java.nio.BufferFactory.newDirectByteBuffer(BufferFactory.java:93)
     at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:68)
     at com.threed.jpct.CompiledInstance.fill(CompiledInstance.java:698)
     at com.threed.jpct.Object3DCompiler.compile(Object3DCompiler.java:136)
     at com.threed.jpct.World.compile(World.java:2037)
     at com.threed.jpct.World.renderScene(World.java:1087)
     at gp.itsolutions.Render.onDrawFrame(Render.java:86)
     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
Not sure what this means, or how to fix it.

Edit: It appears I start my game too fast after I shut it down, when I wait a couple of seconds it does work..  :D
edit2: It happens randomly now...  :-\
Title: Re: Out of memory
Post by: EgonOlsen on February 24, 2011, 05:45:00 pm
Call forceGeometryIndices() before compile(). Your way to enable 4bpp is fine. The call itself doesn't consume one single byte of memory. The conversion happens during the upload process to the GPU. The texture data in memory is always 8bpp no matter which setting you use.

The second exception is an indication that you are not disposing and nullifying everything as needed. Keep in mind that for example
Code: [Select]
a=new int[1000];
a=new int[1000];

hasn't the same memory footprint as

Code: [Select]
a=new int[1000];
a=null;
a=new int[1000];

Apart from all that, you already seem to live on the edge of memory...you won't get very far with this as the game commences IMHO. What's the polygon count of the terrain, what's the size of the texture? Something seems to be too big here...


Title: Re: Out of memory
Post by: Kaiidyn on February 24, 2011, 06:37:47 pm
Yea, I was afraid of that....
I am using a 256x256 texture for heightmap and run it through Terragen (http://93.95.149.126/Terragen.rar), a Heightmap2Serialized object generator (based on wiki page Heightmap (http://www.jpct.net/wiki/index.php/Heightmap)),
Maybe there are some modifications possible in the terrain generation there.
Then I scale the terrain object times 20 (terrain.setScale(20)).
Also when closing my game I run System.gc() in the Activity.onClose(), and it's required to wait for that to done before running game again without the error.

Maybe it is possible to 'stream' the terrain somehow?
Or only load x*x around the player into the memory, and as the player walks, unload the parts of the terrain that are not visible anyway..
Don't think that is easy to do, if at all possible.
Title: Re: Out of memory
Post by: EgonOlsen on February 24, 2011, 09:28:57 pm
A 256*256 texture for the heightmap...ok, but what exactly does this mean for polygon/vertex count? You might want to have a look at the wiki where paulscode wrote a nice tutorial about how to reduce polygon count with free tools. I did this for the terrain in the An3DBenchXL bench and it worked pretty well. Maybe that's an option...
Title: Re: Out of memory
Post by: Kaiidyn on February 24, 2011, 09:51:23 pm
I have been looking at that page before and well,
I really don't like blender, that just doesn't work for me at all.. (+ I cant design for shit =p even in 3dsmax7 back in the day)
Also, I am a Linux user, and those programs are for windows.

Maybe an unappropriated question but could I have the terrain that you used in An3DBenchXL? (at least for testing purposes)
Then I could focus more on the 'more important' stuff and add/change terrain, models etc later.
Title: Re: Out of memory
Post by: EgonOlsen on February 24, 2011, 09:53:33 pm
Sure you can have that one. I'll upload it tomorrow now. I still would like to know the actual polygon/vertex count of your terrain to get an idea of what we are talking about here.

Terrain (ser file (named .mp3) and the texture): http://jpct.de/download/tmp/terrain.7z (http://jpct.de/download/tmp/terrain.7z)

use for example
Code: [Select]
Camera cam = world.getCamera();
cam.setPosition(17552.824f, -1755.2219f, 9189.418f);
cam.rotateY(-0.58f);
cam.rotateX(-0.17f);

as a starting position.

I'm doing this to initialize it:
Code: [Select]
terrain.forceGeometryIndices(true);
terrain.build();
terrain.strip();
Title: Re: Out of memory
Post by: Kaiidyn on February 24, 2011, 10:08:05 pm
Ok, Thanks for the object, really appreciate it.
About the polygon/vertex count.. how would I be able to get that? using the PolygonManager?

Edit: When loading your terrain object, it tells me it's an Unsupported version: 1347093252 and wont load.
Title: Re: Out of memory
Post by: EgonOlsen on February 24, 2011, 10:42:15 pm
You have unzipped the file?
Title: Re: Out of memory
Post by: EgonOlsen on February 24, 2011, 10:43:30 pm
Oh, and you can get both information (vertex/polygon) from the Mesh.
Title: Re: Out of memory
Post by: Kaiidyn on February 24, 2011, 11:23:57 pm
Yea, I unzipped it renamed the file (back to) .ser, rezipped it to use in the same way as I did before...

Will try to get the poly count tomorrow..
Title: Re: Out of memory
Post by: EgonOlsen on February 24, 2011, 11:27:21 pm
Which version of jPCT-AE are you using? The latest beta from the new version thread?
Title: Re: Out of memory
Post by: icarusfactor on February 25, 2011, 09:53:10 am
I was going to enter a new topic but saw this one on the same issue I am having.

Code: [Select]
E/AndroidRuntime( 2692): FATAL EXCEPTION: GLThread 9
E/AndroidRuntime( 2692): java.lang.OutOfMemoryError
E/AndroidRuntime( 2692):        at com.threed.jpct.Texture.loadTexture(Texture.java:742)
E/AndroidRuntime( 2692):        at com.threed.jpct.Texture.<init>(Texture.java:192)
E/AndroidRuntime( 2692):        at com.threed.jpct.molespect.MoleSpect.loadTextures(MoleSpect.java:1364)
E/AndroidRuntime( 2692):        at com.threed.jpct.molespect.MoleSpect.Text2PosTexture(MoleSpect.java:2022)
E/AndroidRuntime( 2692):        at com.threed.jpct.molespect.MoleSpect.TextFormatTexture(MoleSpect.java:1819)
E/AndroidRuntime( 2692):        at com.threed.jpct.molespect.MoleSpect.showElementpage(MoleSpect.java:1673)
E/AndroidRuntime( 2692):        at com.threed.jpct.molespect.MoleSpect$MyRenderer.onDrawFrame(MoleSpect.java:2364)
E/AndroidRuntime( 2692):        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
E/AndroidRuntime( 2692):        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)


I tried the preWarm() option but when I compile it says:
 
Code: [Select]
cannot find symbol
    [javac] symbol  : method preWarm(com.threed.jpct.FrameBuffer)
    [javac] location: class com.threed.jpct.TextureManager
    [javac]          TextureManager.getInstance().preWarm(fb);

While I use "fb" as a global for blitting my text which works fine. It is created like this
in my global section.

private FrameBuffer fb = null;

I use "fb" in multiple functions and works in the rest of the program.


Also, on the memory issue I run a memory checker and i tried:

replacing the texture --- memory usage still grows with each use.
unload and remove the texture then load news ones back in -- memory usage still grows with each use.
flush and reload all textures then add my new texture - memory still grows with each use.
Comment out the replacement of the new texture -- works fine memory stays in green, over and over just fine. Just does not add my modification texture. :(

No success with any of these options will keep trying to figure out why preWarm() is not working.







Title: Re: Out of memory
Post by: EgonOlsen on February 25, 2011, 10:26:59 am
preWarm() can only be found in the latest beta, not in the "official" release. Visit the "new version" thread to download the latest beta's jar. About the memory issue...i'm not 100% sure what you are doing, but if you constantly create new textures that are supposed to replace former ones, try this (taken from here: http://www.jpct.net/forum2/index.php/topic,1920.0.html (http://www.jpct.net/forum2/index.php/topic,1920.0.html)):

Code: [Select]
TextureManager.getInstance().unloadTexture(fb, TextureManager.getInstance().getTexture("texture"));
TextureManager.getInstance().replaceTexture("texture", t);
Title: Re: Out of memory
Post by: Kaiidyn on February 25, 2011, 11:18:46 am
If the preWarm() is only in the latest beta, then thats the one I'm using, as that does work..
I am in school right now, so cant check the polycount stuff yet, will do that when I get to my brother's place,
will be there around like.. I think that will be around 5pm..
Title: Re: Out of memory
Post by: EgonOlsen on February 25, 2011, 12:07:10 pm
If the preWarm() is only in the latest beta, then thats the one I'm using, as that does work..
Well...remember that the .mp3 file in the 7z is actually a zip, not a ser. Maybe that's the problem.
Title: Re: Out of memory
Post by: icarusfactor on February 25, 2011, 06:57:40 pm
I have tried different methods of clearing the data from nulls recycles and garbage collection calls still to no avail. when I try  the removeAndUnload or Unload methods it just make the problem worse or die faster (i.e. the mem usage grows even faster). I have tried the preWarm method does not work at all for my situation.

Code: [Select]
public void Text2PosTexture( String texID, String text , int startx , int starty, int fontsize , int Rcol , int Gcol, int Bcol )
{
Log.d(TAG, "public void Text2PosTexture( String texID ,String text , int startx , int starty, int fontsize , int Rcol , int Gcol, int Bcol )" );
int[] letterpos = new int[1];
         int spacing=0;
         //Log.d(TAG, "text.length="+text.length());
         int[] fontType = new int[512 * 512];   
         int[] blitletter = new int[32 * 32];   

         Bitmap immutable_thatfont = Bitmap.createBitmap( 1024, 1024, Bitmap.Config.ARGB_4444 );
font_table.fontTarget = immutable_thatfont.copy(Bitmap.Config.ARGB_4444, true);

         //choose font size 
switch( fontsize )
   {
                case 1:
//normal 16
                //Log.d(TAG, "16pt");
                fontType = font_table.pixles_16pt;
                spacing = font_table.MEDIUM_FONT_SPACING;
break;
case 2:
//large 32
                //Log.d(TAG, "32pt");
                fontType = font_table.pixles_32pt;
                spacing = font_table.LARGE_FONT_SPACING;
break;           
default:
//small 14
                //Log.d(TAG, "14pt");
                fontType = font_table.pixles_14pt;
                spacing = font_table.SMALL_FONT_SPACING;

break;
}



   //choose color to change to. H W  RGB
   fontType = modBitmapColor( fontType, 512 , 512 , Rcol , Gcol , Bcol );

         //this will convert every leter of the string to a position on the font
         //table .
       for (int n=0;n<text.length();n++)
        {
         letterpos =  Letter2TexturePos( text.substring(n,n+1) );
           //return a blitmap letter to post to blitarray
           blitletter = getBlitLetter( fontType, 512 , letterpos[1] , letterpos[0]  );
           //all fonts are 32x32 chunks will copy to a 1024x1024(6) texture.
           font_table.blitmapZ =  blitIntArray( font_table.blitmapZ , 6, blitletter , startx + (n * spacing),starty, 32 , 32 );
        }

         // Int[] to Bitmap
         font_table.fontTarget.setPixels( font_table.blitmapZ , 0, 1024 , 0, 0, 1024 , 1024 );
  //place font into texture.
         Texture allfonts = new Texture( font_table.fontTarget  , true  );         
         immutable_thatfont.recycle();
         immutable_thatfont = null;
System.gc();
               
        TextureManager.getInstance().unloadTexture( fb, TextureManager.getInstance().getTexture(  texID  ) );
        TextureManager.getInstance().replaceTexture(texID, allfonts );
}


If i comment out the last two lines everything works fine , but it will only  show the background with no text and the memory stays in the safe zone. if I start replacing the texture with the image of my background and text ,it just goes up and up and up until it crashes.

Which would lead me to believe it is the replacement method and not anything else although I now have really cleaned up the mem usage overall, just not the leak.
Title: Re: Out of memory
Post by: EgonOlsen on February 25, 2011, 08:39:01 pm
I can't verify the leak. I wrote myself this little test case. It's based on your method but stripped, because i don't have all this font-stuff. I simply colored the Bitmap in a random color. To tweak memory usage a little bit, i release immutable_thatfont a little earlier (what's the point of that bitmap anyway?) and added Config.unloadImmediately=true at the beginning of onCreate(). However, none of these is actually needed to make it work in the 2.2 emulator.

While playing around with preWarm(), i've noticed one thing that i consider to be a VM flaw: If you add this call at the end of the test2PosTexture-method, it crashes immediately with an OOM-Exception. If you let the method return normally and add the call right after that (like in this example), it works just fine. Looks like as if some memory won't be released even if it could unless the method returns...might be a GC flaw or "optimization".

However, this test case runs as it should for me. What happens in your case and why it goes away if you omit the call to replaceTexture() has to be something else. I *think* that is has to do with the fact that you are running on the edge of memory anyway. You create two large bitmaps, each 4mb in size plus the actual texture using another 4mb plus the memory needed to upload it plus the memory on the gpu (another 4mb) plus the memory that your application itself needs etc. Combine that with the fact that Android/Dalvik starts to act weird when running close to its memory limits especially when working with Bitmaps and you might run into trouble. If you omit the call to replace, there's no new upload and maybe the texture is smaller (don't know, impossible to tell from that code snippet).

Isn't it possible to reduce the size of these monster bitmaps? Lets say to 512*512 or something like that? Why does it has to be that large?

Anyway, here's the test case:
Code: [Select]
package com.threed.jpct.example;

import java.lang.reflect.Field;

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;

import com.threed.jpct.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Logger;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.BitmapHelper;
import com.threed.jpct.util.MemoryHelper;

/**
 * @author EgonOlsen
 *
 */
public class HelloWorld extends Activity {

private static HelloWorld master = null;

private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
private World world = null;
private RGBColor back = new RGBColor(50, 50, 100);

private float touchTurn = 0;
private float touchTurnUp = 0;

private float xpos = -1;
private float ypos = -1;

private Object3D cube0 = null;
private Object3D cube1 = null;
private Object3D cube2 = null;
private Object3D cube3 = null;
private Object3D dummy = null;

// private Texture renderTarget = null;

private TextureManager tm = TextureManager.getInstance();

private int fps = 0;

private int cnt = 0;

protected void onCreate(Bundle savedInstanceState) {

Config.unloadImmediately = true;
Logger.setLogLevel(Logger.LL_VERBOSE);

Logger.log("onCreate");

if (master != null) {
copy(master);
}

super.onCreate(savedInstanceState);
mGLView = new GLSurfaceView(getApplication());

mGLView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
EGLConfig[] configs = new EGLConfig[1];
int[] result = new int[1];
egl.eglChooseConfig(display, attributes, configs, 1, result);
return configs[0];
}
});

renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);
}

@Override
protected void onPause() {
super.onPause();
mGLView.onPause();
}

@Override
protected void onResume() {
super.onResume();
mGLView.onResume();
}

protected void onStop() {
super.onStop();
}

private void copy(Object src) {
try {
Logger.log("Copying data from master Activity!");
Field[] fs = src.getClass().getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
f.set(this, f.get(src));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public boolean onTouchEvent(MotionEvent me) {

if (me.getAction() == MotionEvent.ACTION_DOWN) {
xpos = me.getX();
ypos = me.getY();
return true;
}

if (me.getAction() == MotionEvent.ACTION_UP) {
xpos = -1;
ypos = -1;
touchTurn = 0;
touchTurnUp = 0;
return true;
}

if (me.getAction() == MotionEvent.ACTION_MOVE) {
float xd = me.getX() - xpos;
float yd = me.getY() - ypos;

xpos = me.getX();
ypos = me.getY();

touchTurn = xd / -100f;
touchTurnUp = yd / -100f;
return true;
}

try {
Thread.sleep(15);
} catch (Exception e) {
// No need for this...
}

return super.onTouchEvent(me);
}

protected boolean isFullscreenOpaque() {
return true;
}

class MyRenderer implements GLSurfaceView.Renderer {

private long time = System.currentTimeMillis();
private boolean stop = false;

public MyRenderer() {
}

public void stop() {
stop = true;
}

public void onSurfaceChanged(GL10 gl, int w, int h) {
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(gl, w, h);

if (master == null) {

world = new World();
world.setAmbientLight(255, 255, 255);

Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.icon)), 64, 64));
TextureManager.getInstance().addTexture("texture", texture);
texture.setMipmap(false);

dummy = Object3D.createDummyObj();

cube0 = Primitives.getCube(10);
cube0.rotateY(-(float) Math.PI / 4f);
cube0.rotateMesh();
cube0.clearRotation();
cube0.calcTextureWrapSpherical();
cube0.setTexture("texture");
cube0.strip();
cube0.build();

cube1 = cube0.cloneObject();
cube2 = cube0.cloneObject();
cube3 = cube0.cloneObject();

world.addObject(cube0);
world.addObject(cube1);
world.addObject(cube2);
world.addObject(cube3);

cube0.translate(-20, -20, 0);
cube1.translate(20, -20, 0);
cube2.translate(-20, 20, 0);
cube3.translate(20, 20, 0);

cube0.addParent(dummy);
cube1.addParent(dummy);
cube2.addParent(dummy);
cube3.addParent(dummy);

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 100);

// renderTarget = new Texture(256, 256, RGBColor.RED);

MemoryHelper.compact();

if (master == null) {
Logger.log("Saving master Activity!");
master = HelloWorld.this;
}

// Logger.setLogLevel(Logger.DEBUG);
}
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}

public void onDrawFrame(GL10 gl) {

try {
if (!stop) {
if (touchTurn != 0) {
dummy.rotateY(touchTurn);
touchTurn = 0;
}

if (touchTurnUp != 0) {
dummy.rotateX(touchTurnUp);
touchTurnUp = 0;
}

cnt++;

/*
* Config.autoMaintainAspectRatio=false;
* fb.setRenderTarget(renderTarget);
* fb.clear(RGBColor.BLUE);
* fb.blit(tm.getTexture("texture"), 0, 0, 0, 0, 64, 64,
* fb.getWidth(), fb.getHeight(), -1, false, null);
* fb.display(); fb.removeRenderTarget();
* Config.autoMaintainAspectRatio=true;
*/

text2PosTexture("texture");
// TextureManager.getInstance().preWarm(fb);

fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();

if (System.currentTimeMillis() - time >= 1000) {
Logger.log(fps + "fps");
fps = 0;
time = System.currentTimeMillis();
}
fps++;
} else {
if (fb != null) {
fb.dispose();
fb = null;
}
}
} catch (Exception e) {
Logger.log(e, Logger.MESSAGE);
}
}
}

public void text2PosTexture(String texName) {
Bitmap immutable_thatfont = Bitmap.createBitmap(1024, 1024, Bitmap.Config.ARGB_4444);
Bitmap fontTarget = immutable_thatfont.copy(Bitmap.Config.ARGB_4444, true);
int red = (int) (255d * Math.random());
int green = (int) (255d * Math.random());
int blue = (int) (255d * Math.random());
fontTarget.eraseColor(Color.rgb(red, green, blue));

immutable_thatfont.recycle();
immutable_thatfont = null;

MemoryHelper.compact(); // Actually not needed

Logger.log("Creating new texture!");
Texture allfonts = new Texture(fontTarget, true);
fontTarget.recycle();
fontTarget = null;

Logger.log("Unloading old texture!");
TextureManager.getInstance().unloadTexture(fb, TextureManager.getInstance().getTexture(texName));

Logger.log("Replacing with new texture!");
TextureManager.getInstance().replaceTexture(texName, allfonts);
}
}






Title: Re: Out of memory
Post by: icarusfactor on February 25, 2011, 11:00:42 pm
Add both lines to my app and it works like a charm, thanks.

added header

import com.threed.jpct.Config;

in oncreate

Config.unloadImmediately=true;





Title: Re: Out of memory
Post by: Kaiidyn on February 26, 2011, 08:40:08 am
Vertex count: 390150
Triangle count: 130050
Title: Re: Out of memory
Post by: EgonOlsen on February 26, 2011, 09:32:59 am
Pffffft....no wonder that you run into memory problems. That's way too much...try to reduce this or split it into parts that can be loaded on demand.