• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
polyfrag

Android processing .md2 model java.lang.outOfMemoryError

10 posts in this topic

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

 

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

 

 

in

 


        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

 

    		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

Edited by polyfrag
0

Share this post


Link to post
Share on other sites

va[f].vertices = new CVector3[ numverts ];

 

I'm not primarily a Java programmer, but is this really creating a full object's worth of overhead for each CVector3? It just seems like a lot of memory to me, especially for a mobile device.  Your heap is capping out at 100mb, whereas quake 2 only required 24MB of ram.  Ok, they used 16 bit integers for a lot of it, so double it to 50 MB using 32 bit floats for modern systems.  And this was for multiple models and a full level map.

 

Does Java/Android have any reasonable way to pack it down?  Quake in the old days was in C, so each vector took just 3 floats.  In many ways programming for a mobile device is just like an old PC.

 

You could pack things down into larger allocations:

 

class CVector3Array {

   int capacity;

   int count;

   float[] data;  //constructor will size to  3 * number of vectors

}

 

You would have to implement a few things yourself, and this:

 

vertices.set( i, x,y,z);

 

won't be as elegant as

 

vertices[i] = new CVector3d(x,y,z);

 

But it might end up cleaner than dropping to C.

0

Share this post


Link to post
Share on other sites

I have to agree it looks like a lot of memory, and directly storing the floats rather than using a class is a great way to go.

 

Also, it looks like a lot of verts.  For us it depends on the size of the object in the world, but between 150-200 is the norm and about 500 is the high-end limit.  Of course we potentially have a lot of objects on the screen, but we still end up pushing the limits of much hardware.

0

Share this post


Link to post
Share on other sites

There's 138 vertices but I use glDrawArrays instead of glDrawElements so triangle vertices aren't shared.

 

Then your earlier post has a discrepancy:

 

header.num_frames = 260

numverts = 702

 

 

Your code allocates:

 

 

for(f=0; f<header.num_frames; f++)
    {
        va[f].vertices = new CVector3[ numverts ];
        va[f].texcoords = new CVector2[ numverts ];
        va[f].normals = new CVector3[ numverts ];
 

260 frames * 702 verts = 182'520 items.  I don't know how big your individual classes are, but I'm guessing after allocation and padding and whatnot the classes are 64 bytes big, giving over 11.6MB for that one model.  If they are only 32 bytes big after padding then they are only 5.8MB for that one model.  And that's just the vertex data.

 

That is a huge amount of space for a single model.

 

Out of curiosity, why do you have a different copy of it for every frame?  Are those supposed to be animation frames or something?  Or is it really a completely separate copy of every object?

0

Share this post


Link to post
Share on other sites

Well I need the vertices for hit detection. The rest is stored in VBO. Not every object is important for hit detection though. Not sure how I could further reduce it to get to a Quake 2 level.

 

And they're animation frames of course.

0

Share this post


Link to post
Share on other sites

And they're animation frames of course.

 

Maybe I am missing something here.

 

Why do you need a copy of every vertex, every texture coordinate, and every normal for every animation frame?

 

Most engines use a skinned model.  They only need to store the position and orientation for five or ten bones, and even then they only store it for a few key frames.  Main character models might have in the range of 50 or so bones rather than ten.  But even 50 for a highly articulated model is MUCH less than your 702 entries.

0

Share this post


Link to post
Share on other sites

I know, but I read somewhere that skeletal animations aren't so good on phones. But I guess they were talking about older models. It's a trade-off between memory and CPU I guess. But the engine is all md2 now.

0

Share this post


Link to post
Share on other sites

Agh, I have to port it to NDK because you can't get around the heap memory limit in Java.

Just load texture and model data to the GPU, destroy the objects loaded on the CPU side as soon as the resources is pushed over to OpenGL.

Most android devices use shared memory so there is no disadvantage to storing all model data in VBOs, even if you use keyframes, memory used by OpenGL does not count towards the size limit on the managed heap., The GC will kick in if you run out of memory(But if you still hold references to a bunch of data it can't do much and will throw an exception if you try to allocate more) but once everything is loaded you probably want to "force" garbage collection to reduce the risk of the gc kicking in during gameplay. (you can do this on android by creating a weak reference to an allocated object, set the objects reference to null and then repeatedly call system.gc followed by sleep(1) until the weak reference fails or a timer expires)

You should still aim to use less than 512MB total or you will run into serious issues on older devices. Edited by SimonForsman
0

Share this post


Link to post
Share on other sites

I don't know if I use 512 MB. I have 54 models and one .bsp map loaded at a time.

 

[edit]

 

2.67 MB of models. They're probably under 512 MB in memory because most of them just have 1-2 frames.

Edited by polyfrag
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0