#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    13
    Rep Power
    0

    Android processing .md2 model java.lang.outOfMemoryError


    Why am I getting java.lang.outOfMemoryError on the line

    Code:
        				va[f].normals[index] = new CVector3();
    in


    Code:
            numverts = header.num_tris * 3;
            
        	int index;
    
        	FloatBuffer va2 = FloatBuffer.allocate( numverts * (3 + 2 + 3) );
            float temp;
            int f;
    		CVector3 normal = new CVector3();
    		CVector3 tri[] = new CVector3[3];
    		tri[0] = new CVector3();
    		tri[1] = new CVector3();
    		tri[2] = new CVector3();
    		
            CVertexArray va[] = new CVertexArray[ header.num_frames ];
            
        	for(f=0; f<header.num_frames; f++)
        	{
        		va[f] = new CVertexArray();
        		
        		va[f].numverts = numverts;
        		va[f].vertices = new CVector3[ numverts ];
        		va[f].texcoords = new CVector2[ numverts ];
        		va[f].normals = new CVector3[ numverts ];
                
        		for (i = 0; i < header.num_tris; ++i)
        		{
        			for (j = 0; j < 3; ++j)
        			{
        				index = i*3 + j;
        				
        				va[f].vertices[index] = new CVector3();
        				va[f].texcoords[index] = new CVector2();
        				va[f].normals[index] = new CVector3();
        			}
        		}
        	}
            
            vertexArrays = va;

    It doesn't happen if I comment out any of the other lines

    Code:
        		va[f].vertices = new CVector3[ numverts ];
        		va[f].texcoords = new CVector2[ numverts ];
        		va[f].normals = new CVector3[ numverts ];


    It's the 6th model loaded and
    header.num_frames = 260
    numverts = 702

    Before the stack trace it says:

    03-25 08:33:21.510: I/dalvikvm-heap(22950): Clamp target GC heap from 103.874MB to 96.000MB
    03-25 08:33:22.158: I/dalvikvm-heap(22950): Clamp target GC heap from 103.987MB to 96.000MB
    03-25 08:33:22.814: I/dalvikvm-heap(22950): Clamp target GC heap from 103.987MB to 96.000MB
    03-25 08:33:22.814: I/dalvikvm-heap(22950): Forcing collection of SoftReferences for 20-byte allocation
    03-25 08:33:23.447: I/dalvikvm-heap(22950): Clamp target GC heap from 103.987MB to 96.000MB
    03-25 08:33:23.455: E/dalvikvm-heap(22950): Out of memory on a 20-byte allocation.
    This works fine on the iphone in C++/ObjC
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    13
    Rep Power
    0
    Agh, I have to port it to NDK because you can't get around the heap memory limit in Java.

IMN logo majestic logo threadwatch logo seochat tools logo