Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException when loading md2 model #15

Open
GoogleCodeExporter opened this issue Feb 25, 2016 · 2 comments
Open

ArrayIndexOutOfBoundsException when loading md2 model #15

GoogleCodeExporter opened this issue Feb 25, 2016 · 2 comments

Comments

@GoogleCodeExporter
Copy link

First of all, libgdx is a great and amazing android engine, I love it, I used 
it for my 2d game development now I want to walk into 3d, I test the examples 
that  is very nice when loading .g3d model, but I met some problems when load 
md2 models

What steps will reproduce the problem?
1. I follow the steps and modify the KeyframedModelViewer.java as 
http://code.google.com/p/libgdx-users/wiki/MD2_Keyframe_Animation#Implement_MD2_
in_Game mentioned
2. then I got the error:
Exception in thread "AWT-EventQueue-0" 
java.lang.ArrayIndexOutOfBoundsException: 2160
    at com.badlogic.gdx.graphics.g3d.model.keyframe.KeyframedModel.setAnimation(KeyframedModel.java:150)
    at com.badlogic.gdx.graphics.g3d.test.KeyframedModelViewer.render(KeyframedModelViewer.java:131)、


the code are there                      
final float valSrc = src[srcIdx];
final float valSrc2 = src2[srcIdx++];

I 've no idea with what's wrong with the logic, because it works well for g3d 
models...

What is the expected output? What do you see instead?
To load md2 without any errors

What version of the product are you using? On what operating system?
the latest version of svn sources.
OS: windows 7

Please provide any additional information below.


Original issue reported on code.google.com by clicklee...@gmail.com on 8 Dec 2011 at 3:59

Attachments:

@GoogleCodeExporter
Copy link
Author

I've tried the same code for g3d and .md2 and the code works if you follow the 
instructions. One instruction missing is that when going for .md2 you need to 
add an import to 
import com.badlogic.gdx.graphics.g3d.materials.*;
and everything works, UNTIL,
you try to play animation other than default, which is 0("all")
        anim = (KeyframedAnimation)model.getAnimations()[0];

The sam issue is with g3d animations. So both of us do not know how to start an 
animation other than "all".
I tried my model animation exported from blender and there is the same issue.
If I play [0] animation, all is ok, but if I change it to other, say [2]
I get an error you are pointing out. 

Original comment by miroslav...@gmail.com on 17 Dec 2011 at 4:15

@GoogleCodeExporter
Copy link
Author

Hi, 

i resolved the issue with ArrayIndexOutOfBoundsException problem when playing
selected parts of .md2 keyframe animation.
The workaround is somewhere around line 175 of file MD2Loader.java:
float[] vertices = new float[header.numVertices * 6]; // changed from *3 to *6

and

around line 182, added 3 lines for vertices:
        vertices[idx++] = frame.vertices[idxV++];
        vertices[idx++] = frame.vertices[idxV++];
        vertices[idx++] = frame.vertices[idxV++];

I really hope this is not just a workaround, and that it's not going to create
some other issues :)
Hope this helps someone else...

Original comment by miroslav...@gmail.com on 18 Dec 2011 at 1:46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant