DragonBolt / jmonkeyengine

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

XML parsing in Android problem #361

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Try to run HelloAssets under Android

I got a strange error when trying to run HelloAssets tutorial example on 
Android, it seem to stumble on

Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");

That for some reason makes SkeletonLoader.java use the skeleton object before 
it is initialized, e.g. skeleton is still “null” when that “track” 
start tag is found. I can see that it should be initialized when the end of the 
“bonehierarchy” tag is found, I verified this by adding breakpoint on both 
the endElement() in the “bonehierarchy” section and startElement() in the 
“track” section and the “track” is invoked first.

Looking in into Ninja.skeleton.xml everything seem to be in the right order:

...
    <bonehierarchy>
        <boneparent bone="Joint2" parent="Joint1" />
...
    </bonehierarchy>
    <animations>
        <animation name="Attack1" length="1">
            <tracks>
                <track bone="Joint1">
...
I can also see that it finds start of the “bonehierarchy” tag and the 
“boneparent” tags.

Seems like in

public void endElement(String uri, String name, String qName) {

qName is always null and name gets the end tag name.
In

public void startElement(String uri, String localName, String qName, Attributes 
attribs) throws SAXException {

both localName and qName get the tag name.

I changed to code to use name/localName instead of qName it get passed the XML 
problem, I know to little about XML to know if this is the proper way to fix it 
but it helped me.

I attache an patch...

What version of the product are you using? On what operating system?
SVN From 2011-06-19
Android 2.3.4

Original issue reported on code.google.com by ZingoAnd...@gmail.com on 20 Jun 2011 at 8:11

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks. Generally its advised to load models in the internal j3o format on all 
platforms to avoid unnecessary conversion processes and problems.

Original comment by normen667 on 20 Jun 2011 at 9:19

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
 I found that the bones array is empty prior to creating a skeleton object which results in a null pointer exception.
this can be fixed by creating one in startElement method:

### Eclipse Workspace Patch 1.0
#P jme3
Index: src/ogre/com/jme3/scene/plugins/ogre/SkeletonLoader.java
===================================================================
--- src/ogre/com/jme3/scene/plugins/ogre/SkeletonLoader.java    (revision 7654)
+++ src/ogre/com/jme3/scene/plugins/ogre/SkeletonLoader.java    (working copy)
@@ -128,6 +128,15 @@
             animation = new BoneAnimation(name, length);
         } else if (qName.equals("bonehierarchy")) {
             assert elementStack.peek().equals("skeleton");
+            Bone[] bones = new Bone[indexToBone.size()];
+            // find bones without a parent and attach them to the skeleton
+            // also assign the bones to the bonelist
+            for (Map.Entry<Integer, Bone> entry : indexToBone.entrySet()) {
+                Bone bone = entry.getValue();
+                bones[entry.getKey()] = bone;
+            }
+            indexToBone.clear();
+            skeleton = new Skeleton(bones);
         } else if (qName.equals("animations")) {
             assert elementStack.peek().equals("skeleton");
             animations = new ArrayList<BoneAnimation>();

Original comment by koby.her...@gmail.com on 21 Jun 2011 at 8:46

GoogleCodeExporter commented 9 years ago
Ignore my patch and use the one from kabuki instead see

http://jmonkeyengine.org/groups/android/forum/topic/how-to-run-your-jme3-applica
tion-on-android-androidharness/?topic_page=3&num=15&_wpnonce=2e68ae55e4

Original comment by ZingoAnd...@gmail.com on 26 Jun 2011 at 2:52

GoogleCodeExporter commented 9 years ago
"Generally its advised to load models in the internal j3o format on all 
platforms to avoid unnecessary conversion processes and problems." 

Thanks for the hit, Ill keep that in mind, currently Im in a tutorial mode. I 
see that the startup is seems realy slow with the original formats so I assume 
it will be faster with j3o.

Original comment by ZingoAnd...@gmail.com on 26 Jun 2011 at 2:55

GoogleCodeExporter commented 9 years ago
The issue has been fixed afaik

Original comment by normen667 on 26 Aug 2011 at 10:12