Bug in CloneImportExport.CloneCapsule.readSavableArray(String, Savable[]) ?

Hi all,



not sure if this is the right place to post it, but I think I found a Bug in CloneImportExport.CloneCapsule.readSavableArray(String, Savable[]). When I try to clone a scene graph branch with a geometry (TriMesh) attached to it that has a MaterialState and a TextureState attached to its parent Node, these RenderStates get lost in the cloning process.



(Okay, to illustrate the Structure:

[pre]Node (root)

Node (geometry parent) <-- MaterialState, TextureState

TriMesh[/pre]

).



By debugging I was able to track this issue down to a passage in CloneImportExport.CloneCapsule.readSavableArray(String, Savable[]):


                public Savable[] readSavableArray(String name, Savable[] defVal) throws IOException {
                        if (ignoreField(name)) {
                                return defVal;
                        }
                       
                        Savable[] original = (Savable[]) values.get(name);
                        if (original == null) {
                                return defVal;
                        }
                        if (shallowCopyField(name)) {
                                return original;
                        }
                       
                        Savable[] copy = new Savable[original.length];
                       
                        for (int i=0;i<copy.length;i++) {
                                copy[i] = oldToNew.get(original[i]);
                                if (copy[i] == null) {
                                        copy[i] = create(original[i]);
                                        if(copy[i] == null) {
                                           return null;
                                        }
                                        copy[i].read(CloneImportExport.this);
                                }
                        }
                       
                        return copy;
                }



In line 21 of this excerpt (line 1195 in the source file of CloneImportExport) this method returns null as soon as one of the elements in the array copy is null. When this method parses the list of RenderStates attached to a node, it can therefore only successfully copy and return the list if all RenderStates are set - any one of the saved RenderStates being null will result in the method returning null, that is, no RenderStates at all.

However, I was able to fix this issue for myself by changing the statement [pre]return null;[/pre] to [pre]continue;[/pre] With this change, the method properly cloned the RenderStates and my clone looked as it was supposed to look.

I don't know if there was some greater "master plan" behind this that I don't know of, but if anyone can confirm that this is indeed a bug, I'll post it to the Issue Tracker.

I think I stumbled upon that bug at some point but was too lazy to dig up the reason it happened, basically because I didn't need the RenderStates in that particular situation. (Sorry for that, jME community ://)

Good catch BattleWorm!

Thanks!  :slight_smile:

So, should I add this bug to the Issue Tracker? Or can some developer solve this issue in the release version through a hotfix or something?

Fixed in cvs.