Closed GoogleCodeExporter closed 8 years ago
hmm, i don't quite get it..do you have a simple testcase I could try maybe - or
even a fix?
Original comment by sirhc.f...@gmail.com
on 29 Mar 2011 at 11:53
Yes, it's confusing. Here's what is happening. On line 5 in the listing below
of the MTComponent method, tangibleComp is removed from oldParent. But in the
case that generates the stack trace, oldParent is also a child of the
new parent, "this". And oldParent is set to automatically destroy itself
when all its child components are lost.
So by line 13, the list childComponents has been reduced in length by 1, because
oldParent is no longer in it.
Replacing line 10 with the following would prevent the stack:
i = Math.max(0, Math.min(childComponents.size(), i));
1 public void addChild(int i, MTComponent tangibleComp){
2 MTComponent oldParent = tangibleComp.getParent();
3 boolean sameParent = false;
4 if (oldParent != null){
5 oldParent.removeChild(tangibleComp);
6 if (oldParent.equals(this)){
7 i--;//If we removed the comp from this (same parent) we have to decrease
the index
8 sameParent = true;
9 }
10 i = (i<0)? 0 : i; //ensure i > 0
11 }
12 tangibleComp.setParent(this);
13 childComponents.add(i, tangibleComp);
14
16 if (!sameParent){ //TEST - only mark dirty if comp was added to different
parent
17 //To inform its children, that they have to update their
18 //global matrices, because this new parent could
19 //change it with its own
20 tangibleComp.setMatricesDirty(true);
21 //search up the tree and update the camera responsible for drawing the
component
22 tangibleComp.searchViewingCamera();
23 }
24 //Fire state change event
25 this.fireStateChange(StateChange.CHILD_ADDED);
26 tangibleComp.fireStateChange(StateChange.ADDED_TO_PARENT);
27 }
Original comment by drran...@gmail.com
on 29 Mar 2011 at 3:06
seems to make sense and as I dont have the time to test stuff these days I'm
gonna trust you on this fix and just add it - thx ;)
Original comment by sirhc.f...@gmail.com
on 30 Mar 2011 at 8:41
Original issue reported on code.google.com by
drran...@gmail.com
on 10 Mar 2011 at 12:08