kannan622 / min3d

Automatically exported from code.google.com/p/min3d
0 stars 0 forks source link

md2 number of animation frames overflows memory #33

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Loading MD2 file

What is the expected output? What do you see instead?
It should load md2 file with its animation. It returns out of memory error 
instead.

What version of the product are you using? On what operating system?
Min3D 1_016 on Windows 7.

Please provide any additional information below.
We all know that md2 specification tells us that each model has 198 frames for 
animation. When I was trying to load my model it was returning 
OutOfMemoryError. I even changed the AnimationObject3d constructor in 
AnimationObject3d.java to load only a given number of frames. That worked only 
up to ~70 frames. Further tests for: 75, 80, 90, 120, 150, 170 frames always 
returned OutOfMemoryException. The memory overflow took place in that line:

vertices = new float[indices.length*3];

in KeyFrame.java. Is this only a case of my emulator? I made an upload to my 
real Android device and it still causes outOfMemoryError...

Original issue reported on code.google.com by wiern...@gmail.com on 9 Feb 2011 at 10:50

GoogleCodeExporter commented 9 years ago
And I have to notice that it is not a polycount problem 'cause the effect is 
same for a near 1000 poly model and for simple Box.

Original comment by wiern...@gmail.com on 9 Feb 2011 at 1:06

GoogleCodeExporter commented 9 years ago
What is the output of

int allocation = indices.length * 3 * 8;
Log.e("Allocating Float Array", "bytes: " + allocation);

Original comment by ArturoTh...@gmail.com on 26 Feb 2011 at 9:55

GoogleCodeExporter commented 9 years ago
if you mean number of vertices by indeces it returns:

02-26 23:24:45.271: ERROR/Allocating Float Array(621): bytes: 13824

Original comment by wiern...@gmail.com on 26 Feb 2011 at 10:28

GoogleCodeExporter commented 9 years ago
I found that indices is calculated as header.numTriangles*3, so I checked the 
value you wanted by calculating:

int allocation = header.numTriangles*3 * 3 * 8;

Original comment by wiern...@gmail.com on 26 Feb 2011 at 10:31

GoogleCodeExporter commented 9 years ago
I'm sorry about my previous post - i should have asked:

What is the output of:

# KeyFrame.java
public void setIndices(int[] indices) {
    this.indices = indices;

    int allocation = indices.length * 3 * 4; // 4 bytes per float not 8 my mistake
    Log.e("Allocating Float Array", "bytes: " + allocation);

    float[] compressed = vertices;
    vertices = new float[indices.length*3];

    // rest of method

I only brought this up as I had a somewhat similar issue in AParser.generate() 
where a new int array was declared as such:

# AParser.java -> generate()
int[] pixels = new int[w * h];

Somehow a texture slipped into my project that was 1024x1024 - which attempted 
to allocate 4mb of space and crashed the android runtime.  

Have you attached the Heap tracker to your application process to see how much 
memory is allocated and how much is available?

Original comment by ArturoTh...@gmail.com on 1 Mar 2011 at 6:43

GoogleCodeExporter commented 9 years ago
Here's what happens when I load md2 model with 195 frames:

03-01 19:44:53.266: INFO/dalvikvm-heap(577): Clamp target GC heap from 16.698MB 
to 16.000MB
03-01 19:44:53.297: DEBUG/dalvikvm(577): GC freed 55666 objects / 1387216 bytes 
in 271ms
03-01 19:44:53.366: ERROR/Allocating Float Array blah(577): bytes: 49896
03-01 19:44:53.536: ERROR/Allocating Float Array blah(577): bytes: 49896
03-01 19:44:53.736: ERROR/Allocating Float Array blah(577): bytes: 49896
03-01 19:44:53.936: ERROR/Allocating Float Array blah(577): bytes: 49896
03-01 19:44:54.096: ERROR/Allocating Float Array blah(577): bytes: 49896
03-01 19:44:54.336: INFO/dalvikvm-heap(577): Clamp target GC heap from 17.134MB 
to 16.000MB
03-01 19:44:54.356: DEBUG/dalvikvm(577): GC freed 35984 objects / 906488 bytes 
in 232ms
03-01 19:44:54.516: ERROR/Allocating Float Array blah(577): bytes: 49896
03-01 19:44:54.706: ERROR/Allocating Float Array blah(577): bytes: 49896
03-01 19:44:54.936: INFO/dalvikvm-heap(577): Clamp target GC heap from 17.214MB 
to 16.000MB
03-01 19:44:54.946: DEBUG/dalvikvm(577): GC freed 16540 objects / 414656 bytes 
in 234ms
03-01 19:44:54.946: INFO/dalvikvm-heap(577): Forcing collection of 
SoftReferences for 49912-byte allocation
03-01 19:44:55.136: INFO/dalvikvm-heap(577): Clamp target GC heap from 17.214MB 
to 16.000MB
03-01 19:44:55.146: DEBUG/dalvikvm(577): GC freed 0 objects / 0 bytes in 179ms
03-01 19:44:55.176: ERROR/dalvikvm-heap(577): Out of memory on a 49912-byte 
allocation.

I see your point, but in this case it should be connected with number of 
vertices etc... But that crash happens even when using default example md2 ogro 
from min3D SDK. As I said... it happens even on phone, so it's not the emulator 
fault... How can I attach that Heap tracker? DDMS shows the memory usage like 
above... Please help...

Original comment by wiern...@gmail.com on 1 Mar 2011 at 7:48

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I did some tests which shown that it is exactly the moment of loading md2 
model, when it rises memory usage from around 3 mb to over 16 mb... Even with 
the example one...

Original comment by wiern...@gmail.com on 1 Mar 2011 at 11:19

GoogleCodeExporter commented 9 years ago
The problem has been solved... It was question of too large polycount... over 
1000 polygons is too much for md2 and android platform memory limits... Thanks 
for help :)

Original comment by wiern...@gmail.com on 3 Mar 2011 at 11:34